Python 2.7.1 I am trying to use python regular expression to extract words inside of a pattern
I have some string that looks like this
someline abc
s
You can also use a capture group (?P
and access the group like a dictionary match['user']
.
string = '''someline abc\n
someother line\n
name my_user_name is valid\n
some more lines\n'''
pattern = r'name (?P.*) is valid'
matches = re.search(pattern, str(string), re.DOTALL)
print(matches['user'])
# my_user_name