Posted by mattc at Jul 31, 08 05:05 AM
Posted by mattc at Jul 29, 08 05:05 AM
Posted by mattc at Jul 28, 08 05:05 AM
Posted by mattc at Jul 26, 08 05:05 AM
Posted by mattc at Jul 25, 08 05:05 AM
Posted by mattc at Jul 24, 08 05:05 AM
Posted by mattc at Jul 22, 08 05:05 AM
Posted by mattc at Jul 18, 08 05:05 AM
Posted by mattc at Jul 16, 08 05:05 AM
Posted by mattc at Jul 15, 08 05:05 AM
Posted by mattc at Jul 14, 08 05:05 AM
Posted by mattc at Jul 11, 08 05:05 AM
Posted by mattc at Jul 9, 08 05:05 AM
Posted by mattc at Jul 7, 08 06:18 PM
... Comments (0)
It would be nicer if RegExp objects assigned the mismatched portions of the test string to an array in a similar fashion to which they store portions of successful pattern matches.
var foo = /^[a-z]+$/;
foo.exec("34asdf"); // returns null
So, the developer knows the input string ('34asdf') is invalid but not why. It would much more useful to the calling method to know the specifics of why the string didn't match the pattern and, say, in the cases of interfaces and web forms be able to communicate with precision to the user the reason why their input has failed not just that it has.
Eg. Given the regex test above, it would be useful to be able to look up a failure property that has been populated as a result of the test,
foo.failures = [ "substring '3' found at position 1, expected '[a-z]'", ... ];
I'm not aware of any language that implements regex's doing something like this. In JS you'd have to either throw away your regex pattern and write a lot of custom substring checking functions or split your regex in to multiple parts, but by doing this you lose some of their concise beauty.
Posted by mattc at Jul 6, 08 05:05 AM
Posted by mattc at Jul 5, 08 05:05 AM
Posted by mattc at Jul 4, 08 05:05 AM
Posted by mattc at Jul 3, 08 05:05 AM
Posted by mattc at Jul 2, 08 05:05 AM
Posted by mattc at Jul 1, 08 05:05 AM