I'm pretty new to Python and I know Perl can do this, but I haven't found it in Python yet. What I'm trying to do is to extract a token from a line.
p = re.compile('555=\d+')
ID = p.findall(line)
where line is a single line in a file, and the digits after 555= should be recorded. However, with these two lines, I can only get things like 555=1234567, what I really want is 1234567. Can anyone help and suggest a solution? Thanks!
searchmethod (for only one match) instead offindall(for several matches). You must put your pattern into a raw stringr'555=\d+'or escape the backslashes'555=\\d+'. If you want to only extract the value on the right, use a capture group or, why not a lookbehind (but it's slower).