Given a string made up of 3 capital letters, 1 small caps and another 3 capital ones,
e.g. AAAaAAA
I can’t seem to find a regexp that would find a string which matches a string that has:
- first 3 capital letters all different
- any small caps letter
- first 2 same capital letters as the very first one
- last capital letter the same as the last capital letter in the first “trio”
e.g. A B C a AA C (no spaces)
EDIT:
Turns out I needed something slightly different e.g. ABCaAAC where ‘a’ is the
small caps version of the very fist character, not just any character
The following should work:
For example:
Explanation:
If you want to pull these matches out from a larger chunk of text, just get rid of the
^and$and useregex.search()orregex.findall().You may however find the following approach easier to understand, it uses regex for the basic validation but then uses normal string operations to test all of the extra requirements: