Mehdi Bugnard
Mehdi Bugnard

Reputation: 3979

How match a css style text in C #

I meet problematical for "matcher" css style in a text. I want to get the following style:

style Search

<a id="d325" style="color: #ffffff;"> Visio Infrastructure and Applications </ a>

Regex Used:

Regex myRegex = new Regex(@"<a id=""d(.+?)"" style=""(.+)"" ><\/a>");

I think the problem is style = "color: # fffff" but I just can not understand .

Thanks a lot

Upvotes: 1

Views: 194

Answers (2)

mdelpeix
mdelpeix

Reputation: 187

From my side, you just forget the whitespace in your regex with this one

<a\sid="d(.+?)"\sstyle="(.+)">.*?</a>

you've got the result : 325 and color: #ffffff;

Is the result you want ?

Upvotes: 0

stema
stema

Reputation: 93056

The problems with your regex are

Regex myRegex = new Regex(@"<a id=""d(.+?)"" style=""(.+)"" ><\/a>");
                                                           ^         no space in the string
                                                             ^       the text between the tags is not matched
                                                                ^    there is a space in the string   

The other question is, is a regex the right tool for this job?

Upvotes: 3

Related Questions