PHP preg_split regex不使用点分割

PHP preg_split regex不使用点分割,php,regex,preg-split,Php,Regex,Preg Split,我使用下面的正则表达式将字符串拆分为数组。一切正常,但由于某些原因,它无法使用\(空格)进行拆分。我需要如何更改它才能使其正常工作 $sentences = preg_split(" / (\. |, and|, or|, but|, nor|, so|, for|, yet|after|although|as|as if|as long as|because|before|even if|even though|if|once|provided|since|so that|that|th

我使用下面的正则表达式将字符串拆分为数组。一切正常,但由于某些原因,它无法使用
\(空格)
进行拆分。我需要如何更改它才能使其正常工作

  $sentences  = preg_split(" / (\. |, and|, or|, but|, nor|, so|, for|, yet|after|although|as|as if|as long as|because|before|even if|even though|if|once|provided|since|so that|that|though|till|unless|until|what|when|whenever|wherever|whether|while) /",$sentences); 

由于使用双引号,因此必须对圆点进行双转义。
\\.
而不仅仅是
\.

这里的问题是空格。正则表达式考虑了这一点,因此将其更改为:

$sentences = preg_split("/(\. |, and|, or|, but|, nor|, so|, for|, yet|after|although|as|as if|as long as|because|before|even if|even though|if|once|provided|since|so that|that|though|till|unless|until|what|when|whenever|wherever|whether|while)/",$sentences); 

注意第一个
/
之后和最后一个
/
之前的空格是如何被删除的。

你真的想匹配(空格)(点)(空格)吗?@lvaroG.Vicario我想匹配(点)(空格)@bicycle no
/(\.|,
总是需要前缀空格
\s.
/(\.|,
将解决此问题。这不是真的!双转义仅适用于实际反斜杠字符。@JonathanCairns您确实需要实际反斜杠,在这种情况下可能会误解:@bicycle您想在文本上拆分
\。
?转义斜杠用于您要转义的元素。如果您想转义
`for例如,在PHP中,您需要
\\\\\`两次转义正则表达式的混乱,两次转义字符串lash。
\\.
将匹配“\`后跟一个字母数字字符。哎呀,StackOverflow标记甚至错过了转义:P。我的意思是\\\\\\转义反斜杠,并且该\\将匹配“\”后跟任何字母数字字符。@Allendar我还不能,在您接受之前有一个最小延迟:)