Tuesday, December 22, 2009

Regex Quick Example

This is just another quick example of Regex pattern.

Next pattern matches "at least one symbol which is letter or digit at the begging and then exactly one delimiter '|' and then at least one symbol which is letter or digit in the end":

var valuePattern = new Regex(@"^\w+\|\w+$");
bool isValid = valuePattern.IsMatch(someStringValue);

Valid is:
ab123|cde45
Not valid are:
|ad
df|
adf||adf
and so on...

Links I've used:

Verify your Regex:  
http://www.pagecolumn.com/tool/regtest.htm
Cheat Sheet:
http://www.addedbytes.com/download/regular-expressions-cheat-sheet-v2/pdf/

0 comments:

Post a Comment