I need a regular expression in python which matches exactly 3 capital letters followed by a small letter followed by exactly 3 capital letters. For example, it should match ASDfGHJ and not ASDFgHJK.
r'\b[A-Z]{3}[a-z][A-Z]{3}\b'
This will match what you posted if it is a complete word.
r'(?<![^A-Z])[A-Z]{3}[a-z][A-Z]{3}(?![A-Z])'
This will match what you posted so long as it's not preceded or followed by another capital letter.
here it is:
'[A-Z]{3}[a-z]{1}[A-Z]{3}'
Edited you need to use word boundary also:
r'\b[A-Z]{3}[a-z]{1}[A-Z]{3}\b'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With