I'm using the following regex to split a string to an array. Everything goes fine but for some reason it does not the splitting with \.(space). How would i need to change it to make it work?
$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);
Your whitespace is the issue here. Regular expressions take this into account, so change it to this:
$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);
Note how the whitespace after the first / and before the final / have been removed.
Since you're using double quotes, you have to double escape the dot, so \\. instead of just \.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With