javascript - Grab all html tags from string including their content (Regex Only) -


i trying html tags, without exception, string. clarify, needs strictly string only, without converting html object. created 1 regex grabs the tags without content.

var text = '<div class="mura-region-local"><p>in october 2010, lisa , eugene jeffers learned daughter jade, 2 , half years old, has autism. diagnosis felt double whammy. parents engulfed stress juggling jade’s new therapy appointments , wrangling health insurance provider, had infant son worry about, too. autism runs in families. bradley follow in big sister’s footsteps?</p></div><img href=""/>'    var match = text.match(/<?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[\^'">\s]+))?)+\s*|\s*)?>/g);    console.log(match);

you can't find pairs of <smth>...</smth> possible tags. can't make regex recognize taga inside tagb , tagb in taga tags, too. must write these combinations directly, , makes such regex impossible.

but if mean want take <smth ....>, </smth> , <smth..../> tags without checking correct order of them, possible.

<(?:\w+(?:\s+\w+=(?:"[^"]*"|'[^']*'))*\/?|(?:\/\w+))> 

here test.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -