Wednesday, November 18, 2009

C# Regular Expressions

'*' Matches 0 or more patterns.
(e.g. "*[a]" matches 0 or more 'a's)

'+' Matches 1 or more patterns.
(e.g. "+[a]" matches 1 or more 'a's)

'?' Matches 0 or 1 pattern.
(e.g. "?[a]" matches 0 or 1 'a')

'^' Ignores a pattern.
(e.g. "^a" ignores 'a's)
Also, can be used to signify the start of a string.
(e.g. "^[0-9]" will match a string starting with number)

'[]' Used for range patterns.
(e.g. "[0-9]" matches any number between 0 and 9)

'.' will match any character except '\n'.
(e.g. "a.." matches any 3 letter word starting with 'a')

'\d' matches a digit.
(e.g. "\d"matches any 1 character number)

'$' matches the end of a string.
(e.g. "$[a]" matches a string ending in a)


No comments:

Post a Comment