我的身体内容如下
[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
我正在尝试使用正则表达式提取名称John Doe
,John Doe Junior
,John Doe Junior III
和John
。我几乎可以正常工作了,但似乎无法克服困难
只有一个名称时我的Regex失败
/undefined\]\[i\].\[\/i\].(\w+.+?)?.wrote/
关于如何获取匹配词组的任何想法,这些词组必须写在单词之前而不是贪婪的
答案 0 :(得分:1)
沿着这条线..
\[/i\]\s*(\S+(?:\s+\S+)*?)\s*wrote:
https://regex101.com/r/dGMd0b/1
\[/i\]
\s*
( # (1 start)
\S+
(?: \s+ \S+ )*?
) # (1 end)
\s* wrote: