User Tools

Site Tools


regular_expression_reference

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
regular_expression_reference [2009/01/14 03:48] – created stephenregular_expression_reference [2017/01/01 20:05] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== .NET Regular Expression Reference ======
 +
 +===== Favourite Regexs =====
 +
 +==== Email Address ====
 +
 +<code>
 +^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
 +</code>
 +
 +==== Log4Net Match Thread Id ====
 +
 +<code>
 +^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} \[10\].*?$
 +</code>
 +
 +
 ===== Characters that Match Location in Strings ===== ===== Characters that Match Location in Strings =====
    
Line 26: Line 43:
 | \cC | Matches an ASCII control character—for example, \cC is control-C. | | \cC | Matches an ASCII control character—for example, \cC is control-C. |
 | \u0020 | Matches a Unicode character using hexadecimal representation (exactly four digits). | | \u0020 | Matches a Unicode character using hexadecimal representation (exactly four digits). |
-| \ | When followed by a character that is not recognized as an escaped character, matches that character. For example, \* represents an asterisk (rather than matching repeating characters), and ''\\'' represents a single backslash. |+| \ | When followed by a character that is not recognised as an escaped character, matches that character. For example, \* represents an asterisk (rather than matching repeating characters), and ''\\'' represents a single backslash. |
  
 ===== Wildcard and Character Ranges Used in Regular Expressions ===== ===== Wildcard and Character Ranges Used in Regular Expressions =====
Line 36: Line 53:
 | {n} | The n is a non-negative integer. Matches exactly n times. For example, “o{2}” does not match the “o” in “Bob” but does match the two “o”s in “food”. | | {n} | The n is a non-negative integer. Matches exactly n times. For example, “o{2}” does not match the “o” in “Bob” but does match the two “o”s in “food”. |
 | {n,} | The n is a non-negative integer. Matches at least n times. For example, “o{2,}” does not match the “o” in “Bob” and does match all the “o”s in “foooood”. The sequence “o{1,}” is equivalent to “o+”. The sequence “o{0,}” is equivalent to “o*”. | | {n,} | The n is a non-negative integer. Matches at least n times. For example, “o{2,}” does not match the “o” in “Bob” and does match all the “o”s in “foooood”. The sequence “o{1,}” is equivalent to “o+”. The sequence “o{0,}” is equivalent to “o*”. |
-| {n,m} | The m and n are non-negative integers, where “n <= m”. Matches at least n and at most m times. For example, “o{1,3}” matches the first three “o”s in “fooooood”. “o{0,1}” is equivalent to “o?”. Note that you cannot put a space between the comma and the numbers. |+| {n,m} | The m and n are non-negative integers, where “n ≤ m”. Matches at least n and at most m times. For example, “o{1,3}” matches the first three “o”s in “fooooood”. “o{0,1}” is equivalent to “o?”. Note that you cannot put a space between the comma and the numbers. |
 | ? | When this character immediately follows any of the other quantifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. A non-greedy pattern matches as little of the searched string as possible, whereas the default greedy pattern matches as much of the searched string as possible. For example, in the string “oooo”, “o+?” matches a single “o”, whereas “o+” matches all “o”s. | | ? | When this character immediately follows any of the other quantifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. A non-greedy pattern matches as little of the searched string as possible, whereas the default greedy pattern matches as much of the searched string as possible. For example, in the string “oooo”, “o+?” matches a single “o”, whereas “o+” matches all “o”s. |
 | . | Matches any single character except “\n”. To match any character including the “\n”, use a pattern such as “[\s\S]”. | | . | Matches any single character except “\n”. To match any character including the “\n”, use a pattern such as “[\s\S]”. |
-| ''x|y'' | Matches either x or y. For example, ''z|food'' matches “z” or “food”. ''(z|f)ood'' matches “zood” or “food”. |+| ''x|y'' | Matches either x or y. For example, ''z|food''” matches “z” or “food”. ''(z|f)ood''” matches “zood” or “food”. |
 | [xyz] | A character set. Matches any one of the enclosed characters. For example, “[abc]” matches the “a” in “plain”. | | [xyz] | A character set. Matches any one of the enclosed characters. For example, “[abc]” matches the “a” in “plain”. |
 | [a-z] | A range of characters. Matches any character in the specified range. For example, “[a-z]” matches any lowercase alphabetic character in the range “a” through “z”. | | [a-z] | A range of characters. Matches any character in the specified range. For example, “[a-z]” matches any lowercase alphabetic character in the range “a” through “z”. |
 +
 +===== Characters Used in Regular Expressions =====
 +^ Character ^ Description ^
 +| \d | Matches a digit character. Equivalent to “[0-9]”. |
 +| \D | Matches a non-digit character. Equivalent to “''[^0-9]''”. |
 +| \s | Matches any white-space character, including Space, Tab, and form-feed. Equivalent to “[ \f\n\r\t\v]”. |
 +| \S | Matches any non-white-space character. Equivalent to “''[^ \f\n\r\t\v]''”. |
 +| \w | Matches any word character, including underscore. Equivalent to “[A-Za-z0-9_]”. |
 +| \W | Matches any non-word character. Equivalent to “''[^A-Za-z0-9_]''”. |
 +
 +{{tag>reference regex dot_net}}
regular_expression_reference.1231904909.txt.gz · Last modified: 2017/01/01 19:51 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki