0

我想拆分一个字符串,其中任何字符都是空格或标点符号(不包括撇号)。以下正则表达式按预期工作。

/[^a-z']/i

像我会和没有这样的词被接受了,这很棒。

问题在于像“ere”和“im”这样的词。我想删除开头的撇号并使用 im 和 ere 这两个词。

如果可能的话,我理想地希望在正则表达式模式中停止/删除它。

提前致谢。

4

1 回答 1

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 )
于 2013-01-28T23:27:48.840 回答