Not all Regular Expressions are the same. .Net uses one syntax in the IDE and another at runtime!
Many simple regular expressions can be constructed with this subset of metacharacters. The more advanced the metadata the less likely it is compatible with the target RE engine
^ start of line
$ end of line (also matches \n or \r if MultiLine=True)
? 0 or 1 match
* 0 or more.
+ 1 or more.
{min,max} matches within min max count. E.g. foo{2,3} matches foo 2 or 3 times.
?
non-greedy,
means it stops at the first match not the last:
*?, +?, ??, {min,max}?
(pattern) captures the match into $1..$9 and SubMatches
(?:pattern) non-capturing used for grouping with | (or)
(?=pattern) look ahead. Does not capture or move the starting point of the match.
E.g. (?man) matches fireman, but not firefox
X|Y OR
[xyz] In set of chars, also a-z for ranges [^xyz] not in set.
\b word boundary, look ahead for whitespace, also matches $ (I think)
\B Not word boundary
\d digit[0-9] \D Not a digit
\s whitespace \S not whitespace
\w word char [0-9a-zA-Z] \W not a word char
\t tab
\n newline
\r carriage return
There are many, many attempts at this all over the web. Of course, I think this one is the best. You may disagree, but at least there are enough comments to allow you to see what I was trying to do. It is in a text file, so that you do noyt have to worry about your browser translating my JavaScript.
emailvalidation.txt – js to validate the syntax of email addresses, with comments!
regexpTester2008 Tests regular expression using JavaScript and your browser
regexp-global Tests regular expression using JavaScript and your browser, with global flag On
PathNameParse.xls – Excel 2003 spreadsheet to test parsing of pathnames.
regExpTester-Keyvalue.xls – Excel 2003 spreadsheet to test parsing of query strings, with key value pairs..
These are the routines used to build a generic spreadsheet. Will be adapted to use .NET, someday.
Updated 11/10/2008 6:08:21 PM