Why this regex is not matching the text string?
Question:
I have a python code as follows:
import re
string=" S/O: fathersName,other details,some other details."`
fathersName=re.match(r":.*?,",string).group(0)
The regex match is supposed to match the fatherName
part of the string, but I get a attributr error saying no mathces found
I even tried with re.match(':',string)
and still I get 0 matches.
I think it is somehow related to : symbol, but I’m not sure.
I am using Jupyter Notebook
Answers:
fathersName=re.search(r"S/O:s*(.*?),",string).group(1)
I have a python code as follows:
import re
string=" S/O: fathersName,other details,some other details."`
fathersName=re.match(r":.*?,",string).group(0)
The regex match is supposed to match the fatherName
part of the string, but I get a attributr error saying no mathces found
I even tried with re.match(':',string)
and still I get 0 matches.
I think it is somehow related to : symbol, but I’m not sure.
I am using Jupyter Notebook
fathersName=re.search(r"S/O:s*(.*?),",string).group(1)