Quantcast
Channel: Python extract pattern matches - Stack Overflow
Viewing all articles
Browse latest Browse all 12

Answer by Apalala for Python extract pattern matches

$
0
0

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 all articles
Browse latest Browse all 12

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>