This appendix presents some practical regex patterns that you can use for common matching and validation tasks.
Note |
The following pattern also matches the IP address, but all the groups have been marked as noncapturing: (?:(?:[0-1]?\d{1,2}\.)|(?:2[0-4]\d\.)|(?:25[0-5]\.)){3}(?:(?:[0-1]?\ d{1,2})|(?:2[0-4]\d)|(?:25[0-5])) This is slightly more efficient than the previous pattern, but it's less legible. |
Note |
The following pattern matches the previous one exactly, except that it allows an IP address as well: ^(\p{Alnum}+(\.|\_|\-)?)*\p{Alnum}@(((\p{Alnum}+(\.|\_|\-)?)* \p{Alpha})|((([0-1]?\d{1,2}\.)|(2[0-4]\d\.)|(25[0-5]\.)){3}(([0-1]?\d{1,2})| (2[0-4]\d)|(25[0-5]))))$ For a breakdown of the IP address pattern, please see Table C-1. |
Regex |
Description |
---|---|
\d |
Any number |
{n} |
Repeated n times |
* In English: n digits. Thus, if n was equal to 4, any four digits. |
Regex |
Description |
---|---|
\w |
Any number, any digit, or an underscore symbol |
{n} |
Repeated n times |
* In English: n characters. Thus, if n was equal to 4, any four characters. |
Regex |
Description |
---|---|
\w |
Any number, any digit, or an underscore symbol |
{n |
Repeated n times |
m} |
But not more than m times |
* In English: n characters. Thus, if n was equal to 4 and m was equal to 9, any four, five, six, seven, eight, or nine characters. |
Note |
This regex does not, and cannot, conform to mod 10 verification. To find a Java program that does, please visit http://www.influxs.com. |
Regex |
Description |
---|---|
^ |
Beginning of line, followed by |
[+-]? |
An optional plus or a minus sign |
\d+ |
Followed by one or more digits, followed by |
( |
A group consisting of |
\. |
A period, followed by |
\d+ |
One or more digits |
)? |
Close group, and make it optional |
$ |
End of line |
* In English: Any number of digits followed by an optional decimal component. |