Reputation: 84
Problem: I want to match those strings which contains two digits.Their position is random and a digit should match 2 times.
Example for better understanding my question:
3abc3
a22de
b7abc7a
For these strings it must match.If a string contains two digits but they are different then it shouldn't match.
Example:
3abcd2 not supposed to match 3abc3 -> supposed to match
I tried using {n}, but it not helps, because it thinks the two number follows each other.
Upvotes: 1
Views: 360
Reputation: 785146
You can use this grep
:
grep -E '([0-9]).*\1' file
3abc3
a22de
b7abc7a
About this Regex:
([0-9]) # match and capture any digit in group #1
.* # match 0 or more of any character in between
\1 # using back-reference \1, make sure we have same digit as in group #1
Upvotes: 2