1

I have this regex:

$pattern = '!(>+\h+)?(.*)schrieb:(.*?)!iUgs';

to match

Daniel schrieb:
> I think 

That works. But when I have more than one matching target

Daniel schrieb:
> I think 

Hi,
Jessi schrieb:
> I do
test

the second match will end up in the last catching group, but it should be matched again (but the whole followup, including the second match should be in the last catching group). Is that possible?

I Want to capture

1: Daniel

and

2: 
> I think 

Hi,
Jessi schrieb:
> I do
test

and after that

1: Jesse

and

2:
> I do
test

See: https://regex101.com/r/64Rr52/2

5
  • Or better - what is the final result you expect? Commented Mar 17, 2017 at 9:50
  • like here: regex101.com/r/64Rr52/3 but then it should match "Jessi schrieb" etc. again like the one before Commented Mar 17, 2017 at 9:50
  • Try $pattern = '~(?m)^.*schrieb:\R\h*>.*(?:\R(?!\R).*)*~i' to get the blocks in between double line breaks. Commented Mar 17, 2017 at 9:56
  • none of this works, because I want to capture everything after the "schrieb", so it needs to be captured two times, maybe its not possible Commented Mar 17, 2017 at 10:59
  • I updated my question to illustrate it Commented Mar 17, 2017 at 11:04

1 Answer 1

1

You can use this regex in PHP:

~^(.*?)\h+schrieb:(?=((?s).*\z))~im

(?=((?s).*\z)) is a lookahead that does lookahead assertion and groups text after schrieb: till end of file.

RegEx Demo

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

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.