html - Multi-line regex replace tags inside tags? -


i want replace single-line b/h2/h3/h4/h5 tags inside blockquote tags, h6 tags.

so want this:

^<[b|h[2-5]]>([^\.]+)</[b|h[2-5]]>$ 

to replaced this:

<h6>\1</h6> 

but if it's within blockquote tag, on different lines. i'm thinking solution must involve lookbehind closing blockquote tag , negative-lookbehind opening blockquote, i'm not sure how implement this.

regular expressions extremely bad parsing arbitrary html, many things can go wrong.

that being said: this demo may started.

this doesn't deal edge cases.

<div><b>this thing</div></b> 

will not parse properly.

if know input well-formed , doesn't have deep of nesting (a <b> within <h2> within else, example), may work. parse html, need dom parser.

now, not handle "between blockquote tag" requirement, javascript (if you're using), isn't simple task example. have run same process on , on of elements converted h6.

if use jquery instead, more safely: jsfiddle


Comments