Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to match 3 capital letters followed by a small letter followed by 3 capital letters? [closed]

Tags:

python

regex

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.

like image 238
Nitish Avatar asked Nov 28 '22 18:11

Nitish


2 Answers

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.

like image 63
agf Avatar answered Dec 05 '22 17:12

agf


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'
like image 27
Aamir Rind Avatar answered Dec 05 '22 18:12

Aamir Rind