我想分割一个字符串,其中任何字符都是空格或标点符号(不包括撇号)。以下正则表达式按预期工作。
/[^a-z']/i
我喜欢和不喜欢的词,这很棒。
问题在于像'ere和'im这样的词。我想删除开头的撇号并使用im和ere。
如果可能的话,我最好在正则表达式模式中停止/删除它。
提前致谢。
答案 0 :(得分:1)
试试这个
$str = "Words like I'll and Didn't are accepted, which is great.
The problem is with words like 'ere and 'im";
print_r(preg_split("/'?[^a-z']+'?/i", $str));
//Array ( [0] => Words [1] => like [2] => I'll [3] => and [4] => Didn't ...
// [16] => ere [17] => and [18] => im )