34,333
edits
Changes
→Regular Expressions and Whitespace Characters
<tr>
<td>\\v<td>Vertical tab</td>
</table>
== Matching by Character Type ==
Another useful regular expression trick is to match characters by type or ''class''. For example we might need to specify that a character must be a letter, a number or a alphanumeric. This involves the use of some special class definitions outlines in the following table. Some examples of these special classes in action follow the table:
<table border="1" cellspacing="0">
<tr style="background:#efefef;">
<th>Class Keyword<th>Description of Matches</th>
<td>[:alnum:]<td>Alphanumeric - any number or letter. Equivalent to [a-z], [A-Z] and [0-9]</td>
<tr>
<td>[:alpha:]<td>Alpha - any letter. Equivalent to [a-z] and [A-Z]</td>
<tr>
<td>[:blank:]<td>Space or Tab. Equivalent to [\\t] and [ ]</td>
<tr>
<td>[:cntrl:]<td>ASCII Control Character<td>
<tr>
<td>[:digit:]<td>Numeric. Equivalent to [0-9]</td>
<tr>
<td>[:graph:]<td>Any character with the exception of space</td>
<tr>
<td>[:lower:]<td>Lower case letters. Equivalent to [a-z]</td>
<tr>
<td>[:print:]<td>Any printable character</td>
<tr>
<td>[:punct:]<td>Characters that are neither control characters, nor alphanumeric (i.e punctuation characters)</td>
<tr>
<td>[:space:]<td>Any whitespace character (tab, new line, form feed, space etc)</td>
<tr>
<td>[:upper:]<td>Upper case letters. Equivalent to [A-Z]</td>
<tr>
<td>[:xdigit:]<td>Any hexadecimal digit. Equivalent to [A-F], [a-f] and [0-9]
</table>