In [3]:
from IPython.display import display,HTML
import re
patterns = ['école', 'château']
text = """l'école était située à quelques encablures du château de la patelière,
qui n'avait pas son pareil en splendeur et authenticité dans la région"""
In [4]:
for pattern in patterns:
display(HTML("Searching for [{p}]<br>".format(p=pattern)))
match = re.search(pattern, text)
#Check for match
if match:
display(HTML(text[0:match.start()] +
'<span style="background:yellow">' +
text[match.start():match.end()] +
'</span>' + text[match.end():] ))
else:
display(HTML('<br>No Match was found.<br>'))
In [5]:
def find_regex(text,str_regex):
display(HTML("## find_regex::searching for [{p}]<br>".format(p=str_regex)))
match = re.search(pattern, text)
#Check for match
if match:
display(HTML("<H4>FOUND IT at pos {s} to {e}".format(s=match.start(),e=match.end())))
display(HTML(text[0:match.start()] +
'<span style="background:yellow">' +
text[match.start():match.end()] +
'</span>' + text[match.end():] ))
else:
display(HTML('<br>-- No Match was found.<br>'))
find_regex(text,'château')
In [7]:
text[50:58]
Out[7]:
In [ ]: