How can I split a text into an array of sentences?
Example text:
Fry me a Beaver. Fry me a Beaver! Fry me a Beaver?
Fry me Beaver no. 4?! Fry me many Beavers... End
Should output:
0 => Fry me a Beaver.
1 => Fry me a Beaver!
2 => Fry me a Beaver?
3 => Fry me Beaver no. 4?!
4 => Fry me many Beavers...
5 => End
I tried some solutions that I've found on SO through search, but they all fail, especially at the 4th sentence.
/(?<=[!?.])./
/.|?|!/
/((?<=[a-z0-9)][.?!])|(?<=[a-z0-9][.?!]"))(s|
)(?="?[A-Z])/
/(?<=[.!?]|[.!?]['"])s+/ // <- closest one
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…