How to match a word in python using Regular Expression?

PythonServer Side ProgrammingProgramming

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 = """http://www.google.com/meeting_agenda_minutes.html"""
result = re.findall(r'(?<=[\W_])meeting(?=[\W_])', s)
print result

output

['meeting']
raja
Published on 29-Dec-2017 11:58:26
Advertisements