Reputation: 363
I need to regex that matches a string like LLMM222222. I tried with pattern like (\w{2})(\w{2})2{6}
but it does not work
Upvotes: 0
Views: 180
Reputation: 785846
You can use this regex with 2 back-references:
^([A-Za-z])\1([A-Za-z])\2(\d)\3{5}$
RegEx Breakup:
^
: Start([A-Za-z])
: Match a letter and capture it in group #1\1
: Make sure we repeat same letter using a back-reference #1([A-Za-z])
: Match a letter and capture it in group #2\1
: Make sure we repeat same letter using a back-reference #2\d
: Match and capture a digit in capture group #3\3{5}
: Make sure we repeat same digit 5 more times using a back-reference #3$
: EndUpvotes: 4