【发布时间】:2017-11-27 14:49:53
【问题描述】:
我的正则表达式并不能真正用于在 PHP 中拆分 TitleCase 单词。 没有作者的文章不应受到正则表达式的影响。
我目前的正则表达式: From (\S+\s){2}(?<=[a-z])(?=[A-Z])
这是我的Regex
输入:
From Günther RossmannThis is the article
From Harry Gregson-WilliamsAnother article text
From Nora WaldstättenSome lorem ipsum stuff
From the fantastic architect of the year
Text without an author
预期输出:
<b>From Günther Rossman</b> This is the article
<br>From Harry Gregson-Williams</b> Another article text
<br>From Nora Waldstätten</b> Some lorem ipsum stuff
From the fantastic architect of the year
Text without an author
【问题讨论】:
-
小写字母后没有第二个空格。您可以使用
From (\S+\s\S+)(?<=[a-z])(?=[A-Z])之类的“快速修复”或尝试'~From\s+(\p{Lu}\p{Ll}*\s+\p{Lu}\p{Ll}*)~u'之类的解决方案