2

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?

Interactive demo

2 Answers 2

5

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+ digits
Sign up to request clarification or add additional context in comments.

Comments

1

Try this pattern: ([A-Z])\d\n\1\d\n\1\d.

Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.