I am trying to use javascript's split to get the sentences out of a string but keep the delimiter eg !?.
So far I have
sentences = text.split(/[\\.!?]/);
which works but does not include the ending punctuation for each sentence (.!?).
Does anyone know of a way to do this?
You need to use match not split.
Try this.
The following is a small addition to Larry's answer which will match also paranthetical sentences:
applied on:
giveth:
Try this instead:-
?
is a special char in regular expressions so need to be escaped.Sorry I miss read your question - if you want to keep delimiters then you need to use
match
notsplit
see this question