Javascript and regex: split string and keep the separator -
i have string:
var string = "aaaaaa<br />† bbbb<br />† cccc"
and split string delimiter <br />
followed special character.
to that, using this:
string.split(/<br \/>&#?[a-za-z0-9]+;/g);
i getting need, except losing delimiter. here example: http://jsfiddle.net/jwrz6/1/
how can keep delimiter?
use positive lookahead regular expression asserts special character exists, not match it:
string.split(/<br \/>(?=&#?[a-za-z0-9]+;)/g);
update: fixed typo (moved literal ;
inside lookahead parens)
Comments
Post a Comment