The parentheses () in the regular expression will produce grouping. The grouping can use placeholders to represent the matching value in the expression. The grouping starts from 1.
For example: (d+)-1 中的第一个小括号匹配的是 1 个以上的数字,那么分组1表示为 1,整个表达式可以匹配 123-123 This format separates the numbers before and after with a dash.
And if you add ?: 即表示不产生分组号,此时 (?:d+)-1 匹配的就只是 123-1 in brackets.
Although (?:(?:[0-9]d{2})) looks complicated, it actually just matches 3 numbers.
This brings up the concept of grouping.
The parentheses
()
in the regular expression will produce grouping. The grouping can use placeholders to represent the matching value in the expression. The grouping starts from 1.For example:
(d+)-1
中的第一个小括号匹配的是 1 个以上的数字,那么分组1表示为1
,整个表达式可以匹配123-123
This format separates the numbers before and after with a dash.And if you add
?:
即表示不产生分组号,此时(?:d+)-1
匹配的就只是123-1
in brackets.Although
(?:(?:[0-9]d{2}))
looks complicated, it actually just matches 3 numbers.This should be a 3-digit number from 0 to 9.