Reputation: 7413
I have written a regex
0[\.\-/]0[\.\-/]0
to compare following patterns;
But it also matches
That I don't want. So is there any way to match the already matched sequence?
0[\.\-/]0@10
Upvotes: 1
Views: 66
Reputation: 67988
0([./-])0\\1(0)
You will have to use group
and then backreference
it using \1
.See demo.
https://regex101.com/r/mG8kZ9/3
Upvotes: 1
Reputation: 198476
Yes, as your title says perfectly: groups. Also called captures. Plain parentheses will capture the submatches; backslash-with-number will refer to the captures in order.
0([\.\-/])0\{1}0
or
0([\.\-/])0\1[0]
(because \10
is something else, so we need to use alternate syntaxes or delimit them properly). \1
(or \{1}
) refers to the content between the first open plain parenthesis (i.e. not (?:...)
, not (?=...)
, just (...)
) and its matching closing one.
Upvotes: 1