Reputation: 44086
I have this body content below
[url=undefined][i][/i] John Doe wrote:[/url] Some other random wrote
[url=undefined][i][/i] John Doe Junior wrote:[/url] random stuff again
[url=undefined][i][/i] John Doe Junior III wrote:[/url] random stuff wrote
[url=undefined][i][/i] John wrote:[/url] random stuff wrote
I am trying to pull out the names John Doe
, John Doe Junior
, John Doe Junior III
and John
using regex. I have it almost working but I can't seem to get over the hump
My Regex fails when there is a single name
/undefined\]\[i\].\[\/i\].(\w+.+?)?.wrote/
Any ideas how I can get the matching groups, of any name before the wrote word and not greedy
My test URL is here https://regex101.com/r/pJPbvt/2
Upvotes: 0
Views: 102
Reputation:
Something along these lines ..
\[/i\]\s*(\S+(?:\s+\S+)*?)\s*wrote:
https://regex101.com/r/dGMd0b/1
\[/i\]
\s*
( # (1 start)
\S+
(?: \s+ \S+ )*?
) # (1 end)
\s* wrote:
Upvotes: 1