javascript - Split string ignoring html tags -
is possible split string space "" , ignore html tags in ?
html tags may have style elements : style="font-size:14px; color: rgb(0, 0, 0)" .....
the string i'm talking is:
<div class="line"><span style="color: rgb(0,0,0)">john</span><u> has</u><b> apples</b></div>
if can see have space character inside u
tag , inside b
tag
what trying text split following
<div class="line"><span style="color: rgb(0,0,0)">john</span><u> has</u><b> apples</b></div>
i have following regex not give me rest of string, first 2 parts :
[\<].+?[\>]\s
split using following regexp:
str.split(/ (?=[^>]*(?:<|$))/) [ "<div class="line"><span style="color: rgb(0,0,0)">john</span><u>", "has</u><b>", "apples</b></div>" ]
the ?=
look-ahead. says, "find spaces followed sequence of characters not greater-than signs, less-than sign (or end of string).
the ?:
non-capturing group. need here, because split
has special behavior: presence of capturing group tells include splitters in resulting array of pieces, don't want.
Comments
Post a Comment