Using Regular Expressions Metacharacters with .net – Matching Specific Character Types
Regular Expressions Metacharacters are characters that have special meaning within regular expressions. These metacharacters are said to match classes of characters. Class metacharacters are never actually needed (you can always enumerate the characters to match or use ranges), but you will undoubtedly find them to be incredibly useful. [0-9] is a shortcut for [0123456789] and is used to match any digit. To match anything other than a digit, the set can be negated as [^0-9]. Here are some class shortcuts for digits and nondigits. Similarly for all the alphanumeric characters, A through Z (in uppercase and lowercase), the digits, the underscore, and whitespace characters.
Below table well explain us with the usability of each metacharacter for Matching Specific Character Types.
| Table 1: Regular Expressions Metacharacters for Matching Specific Character Types | |
| meta-character | Definition ( or Use) |
| \d | Any digit (same as [0-9]) |
| \D | Any nondigit (same as [^0-9]) |
| \w | Any alphanumeric character in upper- or lower-case and underscore (same as [a-zA-Z0-9_]) |
| \W | Any nonalphanumeric or underscore character (same as [^a-zA-Z0-9_]) |
| \s | Any whitespace character (same as [\f\n\r\t\v]) |
| \S | Any nonwhitespace character (same as [^\f\n\r\t\v]) |
Caution..??
Regular expression syntax is case sensitive. \d matches digits. \D is the exact opposite of \d. So be cautious while using such Matching Specific Character Types





Comments
No comments yet.
Leave a comment