I have a string:
var string = \"aaaaaa
† bbbb
‡ cccc\"
And I would like to split this string w
If you wrap the delimiter in parantheses it will be part of the returned array.
string.split(/(
?[a-zA-Z0-9]+);/g);
// returns ["aaaaaa", "
†", "bbbb", "
‡", "cccc"]
Depending on which part you want to keep change which subgroup you match
string.split(/(
)?[a-zA-Z0-9]+;/g);
// returns ["aaaaaa", "
", "bbbb", "
", "cccc"]
You could improve the expression by ignoring the case of letters string.split(/()?[a-z0-9]+;/gi);
And you can match for predefined groups like this: \d
equals [0-9]
and \w
equals [a-zA-Z0-9_]
. This means your expression could look like this.
string.split(/
(?[a-z\d]+;)/gi);
There is a good Regular Expression Reference on JavaScriptKit.