My Development Notes

By Haemoglobin
3/10/2010 (revision 1)

Regular Expressions

Regex.IsMatch(input, regex[, RegexOptions.Multiline]); 
Match m = Regex.Match(input, regex); 
m.Groups[i]; 
while(m.Success) {
    m.NextMatch(); 
    m.Result(replaceExpression); 
    Regex.Replace(input, regex, replaceExpression); 
}

RegexOptions

RegexOptions.None
RegexOptions.IgnoreCase(i)
RegexOptions.MultilineChanges meaning of ^ and $ to match beginning and end of each line rather than whole string.
RegexOptions.ExplicitCapture(n) - Specifies that the only valid captures are explicitly named or numbered groups of the form (?&nblt;name&nbgt;?). This allows unnamed parentheses to act as noncapturing groups without the syntactic clumsiness of the expression (?:?).
RegexOptions.CompiledSpecifies that the regular expression is compiled to an assembly. This yields faster execution but increases startup time.
RegexOptions.SingleLine(s) - . matches \n
RegexOptions.IgnorePatternWhitespace(x) and allows comments marked with #
RegexOptions.RightToLeft
RegexOptions.CultureInvariantSpecifies that cultural differences in language is ignored.


MetaCharacters

'
^start (of each line if multiline)
$end (of each line if multiline)
\Aabsolute start
\Zabsolute end (ignoring last \n)
\zabsolute end
\Gmatch after where last match ended
\bword boundary (between \w & \W)
\Bnon-word boundary
\ttab
\x20ASCII
\cCControl C
\u0020Unicode
*0-∞
+1-∞
?0-1
{n}Match n times
{n,m}Match between n and m times
The above appended with ?Non-greedy
.Anything but \n
x|yx or y
[xyz]
[a-z]
\ddigit
\Dnon-digit
\swhite space character
\Snon-white space character
\w[A-Za-z0-9_]
\WOpposite of \w
(?:[xyz])Non-capturing
(?<groupName>[xyz])named group
(?<myGroup>\s\w+)\k<myGroup>Backreference, matches "the the", "the theory"

Substitutions

    \1 matches first group 
    $n
    ${name}
    $$ - $ sign

Comments

Powered by BlogEngine.NET 1.6.1.0 | Design by styleshout | Enhanced by GravityCube.net | 1.4.5 Changes by zembian.com | Adapted by HamishGraham.NET
(c) 2010 Hamish Graham. Banner Image (c) Chris Gin