TAGS :Viewed: 17 - Published at: a few seconds ago
[ How to find a group of consecutive leters and check cases with python re ]
How can I do a re.findall()
that looks for a group of 7 letters where the first 3 and the last 3 are all uppercase and the one in the middle is lowercase? So far, I've tried this:
word1 = "".join(re.findall("[A-Z][A-Z][A-Z][a-z][A-Z][A-Z][A-Z]\d{3}","mystring")
]
However, it doesn't output anything.
How can I do this query?
Thanks!
evamvid
Answer 1
Well, this works for me
p = re.compile(r"[A-Z]{3}[a-z][A-Z]{3}")
word = "".join(re.findall(p, 'udkehtEOajidfEEfjaiERBdEHY alijdfilaOEPvOEG'))
output:
>>> print word
'ERBdEHYOEPvOEG'
Of course, if you were actually searching in "mystring"
, you would naturally get no matches.