PHP preg_split()模式用于按句子分割,除了按浮点数/价格中的句点分割

I would like to be able to preg_split content by periods after sentences i.e.

Lorem ipsum dolor sit 3.14 amet, elit. Vivamus sed elit eu. Morbi pulvinar dignissim.

should output (dots in floats shouldn't be split):

array(
  'Lorem ipsum dolor sit 3.14 amet, elit',
  'Vivamus sed elit eu',
  'Morbi pulvinar dignissim'
)

not

array(
  'Lorem ipsum dolor sit 3',
  '14 amet, elit',
  'Vivamus sed elit eu',
  'Morbi pulvinar dignissim'
)

any ideas how the preg_split pattern should looks like? cheers

This one may work

$res = preg_split('/\.[^\d]/', $str);

The following works on your example, but I'm not sure it'll always do the job, but hope you can use it: "/\.[^$|\d]/"

In case you only want to split in case there's a space or end of string after the dot:

$res = preg_split('~\.( |$)~', $str);

This can give you empty results, which you can drop by setting the PREG_SPLIT_NO_EMPTY flag.

$res = preg_split('~\.( |$)~', $str, 0, PREG_SPLIT_NO_EMPTY);

See as well preg_split.