Javascript and regex: split string and keep the separator -


i have string:

var string = "aaaaaa<br />&dagger; bbbb<br />&dagger; 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); 

see in action.

update: fixed typo (moved literal ; inside lookahead parens)


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -