New to using re. Search for a number before a string.

Justin Barber jbarber at
Sat Nov 2 14:03:10 CET 2013

I'm guessing that the name "FUDD, ELMER" varies. In that case, you might try something like this:

>>> id_num_regex = re.compile(r'\d+(?=\w+\b,.+?)')
>>> id_num_regex.findall(t)

This would account for first names such as 'Mary Ann' and also automatically matches characters only to the end of the line, since you have not flagged re.DOTALL.


More information about the Python-list mailing list