编辑我解决我的问题。这就是解决方案
$string = "Hello my Name is Paloppa. Im' 20 And? Hello! Words I Io Man";
// Word boundary before the first uppercase letter, followed by any alphanumeric character
preg_match_all( '/(?<!^)\b[A-Z][a-z]{1,}\b(?!["!?.\\\'])/', $string, $matches);
print_r( $matches[0] );
现在我还有一个问题
每当它找到一个单词时,该单词就被插入到数组的某个位置。
如果我有这样一句话:“你的名字和姓氏是什么?我的名字和姓氏‘是保罗·西里奥和意甲联赛25号感恩节兄弟”,这是我的密码
$string = "Whats is your Name and Surname? My Name And Surname' is Paolo Celio and Serie A Iim 25 Thanksbro Bro Ciao";
// Word boundary before the first uppercase letter, followed by any alphanumeric character
preg_match_all( '/(?<!^)\b([A-Z][a-z]+ +){1,}\b(?!["!?.\\\'])/', $string, $matches);
print_r( $matches[0] );
输出如下所示
Array (
[0] => Name
[1] => Name And Surname
[2] => Paolo Celio
[3] => Serie
[4] => Iim
[5] => Thanksbro Bro
)
为什么它不加入意甲,而不是甲级联赛?为什么最后一个词没有出现在输出中?
谢谢
编辑我解决我的问题,这是我的REGEX
preg_match_all('/(?<!^)\b[A-Z]([a-z0-9A-Z]| [A-Z]){1,}\b(?!["!?.\\\'])/', $string, $matches);
https://stackoverflow.com/questions/56559605
复制相似问题