Quantcast
Viewing latest article 8
Browse Latest Browse All 12

Answer by Apalala for Python extract pattern matches

You could use something like this:

import res = #that big string# the parenthesis create a group with what was matched# and '\w' matches only alphanumeric charactesp = re.compile("name +(\w+) +is valid", re.flags)# use search(), so the match doesn't have to happen # at the beginning of "big string"m = p.search(s)# search() returns a Match object with information about what was matchedif m:    name = m.group(1)else:    raise Exception('name not found')

Viewing latest article 8
Browse Latest Browse All 12

Trending Articles