0

I need a regex to find this pattern in HTML page for tag <a>. Each <a> has this structure :

   <a rel="EUR,USD,1,2" href="/currencycharts/?from=USD&amp;to=EUR">0.90043</a>

what is problem : my pattern for regex is this :

  @"<a\s.*?rel=.*?href=""/currencycharts/?from=.*?;to=.*>\d.\d\d\d\d ?</a>

but I can not find the <a>.

Harry
  • 1,967
  • 3
  • 22
  • 42
  • possible duplicate of [Reference - What does this regex mean?](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Heretic Monkey Jun 05 '15 at 16:24
  • Parsing HTML with regex is like using a hammer when you need a screwdriver. It's the wrong tool for the job: http://stackoverflow.com/a/1732454/945456 – Jeff B Jun 05 '15 at 18:18

2 Answers2

1

Not knowing your other examples, I would start with this.

<a\s.*?rel=.*?href="/currencycharts/\?from=.*;to=.*>\d\.\d+ ?</a>

?from needs to be \?from

\d.\d\d\d\d has 4 numbers after the decimal, but in your example, you have 5. I would suggest \d\.\d+ or \d\.\d* *Also note the \. instead of .. This will match the period character exclusively instead of 'any' character.

Also, as a note, there are online regex testers that help to quickly diagnose issues with regex patterns. Here is one for C#: http://regexstorm.net/tester

Wyatt Earp
  • 1,644
  • 13
  • 23
0

Use the following:

<a\s.*?rel=.*?href=""/currencycharts/\?from=.*?;to=.*?>\d\.\d\d\d\d\d?</a>
                                     ↑               ↑   ↑          ↑

See DEMO

karthik manchala
  • 13,025
  • 1
  • 27
  • 54