0

From the html source file i've to identify tag with inline style attribute using java.

For example

<span id="abc" 
 style="font-size:11.0pt;font-family:'arial black','sans-serif'; color:#5f497a">

Please help

Oded
  • 489,969
  • 99
  • 883
  • 1,009
Roshan
  • 2,019
  • 8
  • 36
  • 56
  • 1
    Don't use RegEx to parse HTML. Obligatory link: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Oded Aug 17 '10 at 08:34

2 Answers2

2

http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html

Do not parse HTML with regex. Use a proper HTML parser (there are tons out there for Java), and extract the desired data from the DOM tree.

tamasd
  • 5,747
  • 3
  • 25
  • 31
1

Using a regex is one way to do it, eg.

/<span[^>]*style=.*?>/

Or alternatively, if the HTML is well formed, load it using a parser and then use an XPath.

//span[@style]
a'r
  • 35,921
  • 7
  • 66
  • 67