-1

My regular expression works well when there is a space after the dot.

$str = 'Fry me a Beaver. Fry me a Beaver! Fry me a Beaver? Fry me Beaver no. 4?! Fry me many Beavers... End';

$sentences = preg_split('/(?<=[.?!])\s+(?=[a-z])/i', $str);

But I need it to work as well, when there is a \n after the dot.

$str = 'Fry me a Beaver. Fry me a Beaver!\nFry me a Beaver? Fry me Beaver no. 4?! Fry me many Beavers... End';

I can't add a \n to the regular.

Ieeshka
  • 9
  • 4

1 Answers1

-1

You can simply add an \\n, chained to your \s with an OR (|):
/(?<=[.?!])\s+|\\n+(?=[a-z])/i

This can be seen working here.

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71