I'm having a hard time understanding Regular Expressions in Python.
else:
#REGEX1
ret = re.search(r'name:(?P<scname>)',line)
if(ret != None):
print('The name is'+ret.group("scname"))
else:
#REGEX2
ret = re.search(r'(?P<content>)',line)
print('The content is'+ret.group("content"))
I'm parsing a text file with the following content
name:english
1001Nights
A Night at the Call Center
Grammar
name:science
Engineering
Biology
Physics
name:maths
Algebra
Geometry
I want the output to be
The name is english
The content is 1001Nights
The content is A Night at the Call Center
The content is Grammar
The name is science
The content is Engineering
The content is Biology
Please help me correct my regex and suggest any link to understand regular expressions more easily. The official documentation feels a bit overwhelming since I'm new to Python
UPDATE
This is the error I get , if it helps
The subclient name is
Traceback (most recent call last):
File "create&&bkp.py", line 32, in <module>
print('The subclient name is'+ret.group("scname"))
IndexError: no such group