Reputation: 83
I was tried to write regex in Sublime Text that find three match in
A1
A2
A3
B1
B2
B3
C1
C2
C3
1 match
A1
A2
A3
2 match
B1
B2
B3
3 match
C1
C2
C3
Of course, It can be handled with for example
((?:A\d\n)+|(?:B\d\n)+|(?:C\d\n)+)
Is there more smart approach to do it instead of just enumerating?
Upvotes: 2
Views: 3085
Reputation: 626690
You may use
^([A-Z])\d+(?:\R\1\d+)*
See the PCRE regex demo (SublimeText3 uses PCRE regex engine).
Details
^
- start of a line([A-Z])
- Group 1: any ASCII uppercase letter (just note that if Case sensitive option is off, this will also match lowercase letters)\d+
- 1+ digits(?:\R\1\d+)*
- zero or more repetitions of:
\R
- a line break\1
- the same letter as in Group 1\d+
- 1+ digitsUpvotes: 5