A group in a regular expression serves a number of different possible purposes:
- To denote repetition (of more than a single character)
- To restrict alternation to a part of the regular expression
- To capture a value
A group in a regular expression serves a number of different possible purposes:
Groups may be repeated using any of the quantifiers. The regular expression that tentatively identifies an IP address can be improved using a repeated group. The starting point for this expression is as follows:
[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+
In this expression, the [0-9]+ term followed by a literal . character is repeated three times. Therefore, the expression can become as follows:
([0-9]+\.){3}[0-9]+
The expression itself is not very specific—it will match much more than an...