regular expressions help

Pradeep Patra smilesonisamal at gmail.com
Thu Sep 19 03:50:15 EDT 2019


Hi all,

I was playing around with regular expressions and testing the simple
regular expression and its notworking for some reason.

I want to search "my-dog" at any of the place in a string and return the
index but its not working. I tried both in python 3.7.3 and 2.7.x. Can
anyone please help?
I tried re.search, re.finditer, re.findall and none of them is not working
for me.
import re

mystr= "where is my-dog"

pattern=re.compile(r'^my\-dog$')
matches = re.search(mystr)

print(matches)

In the above example both cases(match/not match) the matches returns "None"

I tried re.finditer() and then a loop to find all the occurences of the
pattern in the string but even if there is no error but i could not find
the match.

Can anyone help me in this regard?

Regards
Pradeep



More information about the Python-list mailing list