You are viewing limited content. For full access, please sign in.

Question

Question

Pattern Matching : Need expression's help

asked on April 18, 2018

Hi all!

 

I need your help about a pattern matching.

This is my text

TITLE1
Line 1 and some texts
Line 2 and nothing
Line 3
John DOE
Line 4
TITLE2
Line 1 and some texts
Line 2 and nothing
Line 3
Olivier
Line 4
TITLE2
Line 1 and some texts
Line 2 and nothing
Line 3
Moana
Line 4
TITLE3

 

And I want to get all between Line 3 and Line 4 from TITLE2 (Olivier;Moana).

 

I tried this

(?s)TITLE2.*Line 3\s?\r?\n?(.*[^\s\r\n])\s?\r?\n?Line 4.*TITLE3

 

But it return only "Moana" even if I selected all matches.

 

0 0

Answer

SELECTED ANSWER
replied on April 19, 2018

Hi Oliver,

This worked for me:   (?s)TITLE2.*?(?:Line 3.+?)(\w+)

 

~ Andrew

 

2 0
replied on April 19, 2018

Hi Andrew

 

It's working! Thank you very much.

Regards

1 0
replied on April 24, 2018

Andrew,

 

Your solution doesn't work with a compound noun like "Jean Christophe"

 

0 0
replied on April 25, 2018

You can replace the end of the regex (\w+) to match more than just a single word.
Options to try:
(?s)TITLE2.*?(?:Line 3.+?)(.+?)\n
(?s)TITLE2.*?(?:Line 3.+?)(\w+\s?\w+)

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.