我想拆分字符串,其中任何字符都是空格或标点符号(不包括撇号)。下面的正则表达式按预期方式工作。
/[^a-z']/i像I‘’ll和‘ll’t这样的词都被接受了,这很棒。
问题出在像'ere‘和'im’这样的词上,我想去掉开头的撇号,改成‘im’和‘ere’。
理想情况下,如果可能的话,我希望在regex模式中停止/删除它。
提前谢谢。
发布于 2013-01-29 07:27:49
尝尝这个
$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 )https://stackoverflow.com/questions/14572848
复制相似问题