asp.net - Regular Expression to find span tag with inline style -


i need little write regular expression can find span tag if has inline style in it.

so far have got ]style=[\"'][^\"'][\"']*|/)?> find span tag inline style. can detect span tag when there inline style in not matching ending span tag please see screenshot shows detects in sample textenter image description here

as can see screenshot, first thing detects "" don't want. want work when there inline style present in span tag , corresponding end span tag.

can please me change need make want?

the idea here trying strip out tag when there inline style present in if there span tag class fine.

soapbox

we craft regex match specific case, given html parsing there number of edge cases not picked regex. you'd best off using dom or using product html agility (free)

however

if have basic need capture match try:

((<span\b[^>]*\s\bstyle=(["'])([^"]*)\3[^>]*>)(.*?)</span>)

i'm populating following groups:

  1. gets entire string start end tag
  2. gets entire open tag
  3. gets open single/double quote style value. useless outside of regex, i'm using ensure capture correct closing qoute @ end of value string @ ref 1.
  4. gets value found in style key/value set
  5. gets characters inside span tag.

note break if there nested span tags. enter image description here

enter image description here


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -