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 text
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:
- gets entire string start end tag
- gets entire open tag
- 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.
- gets value found in style key/value set
- gets characters inside span tag.
note break if there nested span tags. 

Comments
Post a Comment