Roshan
Roshan

Reputation: 2059

regex to identify inline style attributes in the HTML tag

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

Upvotes: 0

Views: 2741

Answers (2)

tamasd
tamasd

Reputation: 5913

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.

Upvotes: 2

a&#39;r
a&#39;r

Reputation: 36999

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]

Upvotes: 1

Related Questions