How to get the next line of the match usung regex in python

Viewed 43
Full name: Ajith Kumar
    First name :
       Ajith, aka actor
    Last name :
       Kumar 
    Age :
       55

So here, I want to write a code in python using regex to fetch the string "First name :".

When it matched the string then we should get next line I.e Ajith, aka actor.

Same for Last name as well.

I have written a code I.e ^.*\burst name[\s:]*(\b.*$) Bit it's not showing anything.

1 Answers

Try this:

import re
your_string = '''
Full name: Ajith Kumar
    First name :
       Ajith, aka actor
    Last name :
       Kumar 
    Age :
       55'''
re.findall(r'First name :\n\s+([\w,\s]+)\n', your_string)

Output:

['Ajith, aka actor']

Similar for last name.

Related