Regular Expression To Match 3 Capital Letters Followed By A Small Letter Followed By 3 Capital Letters?
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
Solution 1:
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.
Solution 2:
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'
Solution 3:
re.findall(r'[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]', data)
Solution 4:
This is will check that one small character is exactly present between 3 capital characters on both sides.
I have used lookahead and lookbehind to ensure that exactly three capital characters are on both sides.
r'(?<![A-Z])[A-Z]{3}[a-z][A-Z]{3}(?![A-Z])'.
Solution 5:
>>>import re>>>pattern = r'^[A-Z]{3}[a-z]{1}[A-z]'>>>re.match(pattern , "ABCaABC").start()
0
>>>print re.match(pattern , "ABCABC")
None
>>>print re.match(pattern , "ABCAABC")
None
>>>print re.match(pattern , "ABCAaABC")
None
>>>print re.match(pattern , "ASDFgHJK")
None
>>>print re.match(pattern , "ABCaABC")
<_sre.SRE_Match object at 0x011ECF70>
r'^[A-Z]{3}[a-z]{1}[A-z]'
^ ->Start with capital, so First three letters must be capital.
Post a Comment for "Regular Expression To Match 3 Capital Letters Followed By A Small Letter Followed By 3 Capital Letters?"