![]() |
VOOZH | about |
/#[MNOPQ]-\d\d\d/The above given character string will be match as below.
#M-12345 #N-66666Here, we can also make the use of quantifiers by putting that on the character class. Example:
/#[MNOPQ]-\d{5}/
The above-given example is same as the previous regex and it allows any number of digits after the dash and it can be written as /#[MNOPQ]-\d+/.
The second method is used in the larger character classes. The \d is put in square bracket and match single character digit.
Example:
[\dABCDEFDEFGHIJKLMN]There can be match a single digit or match any of the capital letters A, B, C, D, E, F, G, H, I, J, K, L, M or N. It can be written in shorter form by using dash(-). Then it will be like:
[\dA-N]
$string =~ /[[:class:]]/Here class can be alpha, alnum, ascii etc. POSIX character classes support larger bracketed character classes as shown below:
[01[:Class:]%]Here it will match '0', '1' and any Character Classes and the percent sign. Perl provides support for different PO SIX character classes as shown below in table:
| Class | Description |
|---|---|
| alpha | Any alphabetical character ("[A-Za-z]") |
| alnum | Any alphanumeric character ("[A-Za-z0-9]"). |
| ascii | Any character in the ASCII character set. |
| blank | A space or a horizontal tab |
| cntrl | Any control character. |
| digit | Any decimal digit ("[0-9]"). |
| graph | Any printable character, excluding a space |
| lower | Any lowercase character ("[a-z]") |
| punct | Any graphical character |
| space | Any whitespace character |
| upper | Any uppercase character ("[A-Z]") |
| xdigit | Any hexadecimal digit ("[0-9a-fA-F]") |
| word | A Perl extension ("[A-Za-z0-9_]"), equivalent to "\w" |
| Character Class | Negated | Meaning | Description |
|---|---|---|---|
| \d | \D | [^\d] | matches any non-digit character |
| \s | \S | [^\s] | matches any non-whitespace character |
| \w | \W | [^\w] | matches any non-“word” character |
\p{...any character...}
This syntax is used to match a single character from one of the groups. If you need to match anything except a specified character then you can use the corresponding \P{...any character...} expression.