Computer >> Computer tutorials >  >> Programming >> Python

How to match a word in python using Regular Expression?


The following code matches the word ‘meeting’ in the given string.

It uses positive look-ahead and look-behind assertions to respect enclosing characters but without including them in the match.

Example

import re
s = """https://www.google.com/meeting_agenda_minutes.html"""
result = re.findall(r'(?<=[\W_])meeting(?=[\W_])', s)
print result

output

['meeting']