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

Asked By: akashKP

||

Answers:

fathersName=re.search(r"S/O:s*(.*?),",string).group(1)

Answered By: Gedas Miksenas
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.