1
< br/>

My name is Jonas< br/>

< br/>

How to extract: My name is Jonas

Using regex :

regex = re.findall(r"< br/>\ n.*< br/>\ n< br/>")

Added additional spaces cause otherwise stack would not able to read correctly. But overall code doesn`t do what i want.

2 Answers 2

1

In fact you have more than one break line \n so instead you can use \n* which mean zero or more break line.
Beside you have to use \n and not \ n

try to use this regex < br/>\n*(.*)< br/>\n*< br/>

regex demo

and try this :

import re

line = "< br/>"\
""\
"My name is Jonas< br/>"\
""\
"< br/>";
print(re.findall('< br/>\n*(.*)< br/>\n*< br/>', line));
=> ['My name is Jonas']

Live demo

Sign up to request clarification or add additional context in comments.

1 Comment

FYI: Constructing a character class for a newline character alone, isn't necessary.
0

Have a look at the documentation of the regex groups in python: https://docs.python.org/2/library/re.html

regex = re.findall(r"< br/>\n(.+?)< br/>\ n< br/>")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.