I am using the following, to split some text at either .?!:;
and keep the delimiter :
var str = 'Hello! Here is a file. It is called beatles.mp3. And so on!';
let arr = str.match(/[^\/.?!:;]+(?:[\/.?!:;]|$)/g);
// output ==> ["Hello!", "Here is a file.", "It is called beatles.", "mp3.", "And so on!"]
This is fine, but I'd like to have a way to say (and, just as I do now, keep the delimiter):
"Split everywhere where there is a .
, but if there is a .
followed by mp3
, I'd like you to keep the full .mp3
. Anywhere else, split where there's a .
"
Wanted output:
["Hello!", "Here is a file.", "It is called beatles.mp3.", "And so on!"]