PDA

View Full Version : RegExp: Partial matches



plalx
7 Nov 2011, 1:59 PM
Is there anyone that knows a library in JS that supports partial RegExp matching. For example, where /allo/.test('all') would return true. That would allow doing dynamic input validation while the user is typing simply by defining a regex pattern.

Thanks

skirtle
7 Nov 2011, 6:02 PM
Could you explain a little more about what you mean? From your example it isn't clear why you'd want to use a RegExp. Would there be a list of acceptable values? Strikes me that with a few lines of code you could come with something that converts a list of values into a starts-with RegExp.

Your use case sounds like a ComboBox with forceSelection: true, typeAhead: true and hideTrigger: true.

plalx
8 Nov 2011, 5:12 AM
Hi,

No, there would not be any ways of having a list of values. Partial regex matching can be used to enforce specific masks on input. For example, I could write a regex that validates postal codes. Then, with a partial match (could possibly match), I would be able to validate the use input while he's typing. It's always possible to modify the regex so that it does what I need, but that adds a lot of complexity into it and it's not a generic solution. I know that there are librairies that supports input masking, but not with plain regexs. I already did a simple implementation that works with really basic regexs. It will basically do a mutation of full regex while you type, but it doesn't work with advanced regex patterns and it would require a lot of effort to do so...

What I mean is something like this but for JS: http://www.boost.org/doc/libs/1_34_1/libs/regex/doc/partial_matches.html


(http://www.boost.org/doc/libs/1_34_1/libs/regex/doc/partial_matches.html)

mitchellsimoens
8 Nov 2011, 9:56 AM
http://www.sencha.com/forum/showthread.php?153052-Appropriate-Forum

plalx
8 Nov 2011, 11:39 AM
http://www.sencha.com/forum/showthread.php?153052-Appropriate-Forum

Sorry... Could you move it to the right forum? Thanks

mitchellsimoens
8 Nov 2011, 11:49 AM
Sorry... Could you move it to the right forum? Thanks

Sure, which one would you like?

plalx
9 Nov 2011, 6:05 AM
Q&A I guess?

mitchellsimoens
9 Nov 2011, 6:08 AM
Q&A I guess?

of which framework?

plalx
9 Nov 2011, 6:35 AM
I see your point, it's not really directly related to any sencha features, that's why I posted in the community discussion forum.
Now if you think it shouldn't be here, you are free to delete the post.

Thanks.