-2

I would like to match string of two consecutive alphabets like AA, BB not AB, BD. Python 3.x is my language. Please consider valid alphabets would be capitalized. The followings are examples for valid and not valid strings: To be honest, ^[A-Z]{2} would not work.

  • Valid: AA, ZZ, DD, EE,
  • Not valid: AB, DDD, aA, Aa, Cd, DE
Sang-il Ahn
  • 113
  • 7

1 Answers1

3

You can use grouping to achieve that.

Here is a RegEx that will match any uppercase alphabetical character twice : ([A-Z])\1

Demo.

Zenoo
  • 12,670
  • 4
  • 45
  • 69