-1

I am using HTMLAgilityPack to get some classes and then from the innerText of the classes I want to get a collection of a Regex matches.

My string looks like this:

somestring<b>Test:<br>
EUR/USD - &quot;Expect for <i>PRICE BREAKOUT</i>&quot;<br>
Sell : 1.06809<br>
Target : 1.06309<br>
Stop Loss : 1.07309</b><br>rest of html

and my Regex looks like this

MatchCollection matches = Regex.Matches(sString, @"<b>(.*?)</b>");

However there is not a match. Normally in the text there should be 5 results(the string above repeats itself with slightly changes). There must be something with the special characters that I am missing but I cant seem to figure it out.

Please lend me a hand here. I know its a noobie question but its a bit tricky for me.

Thank you in advance

Sid
  • 11,198
  • 6
  • 35
  • 45
John P.
  • 967
  • 1
  • 8
  • 28
  • 4
    `MatchCollection matches = Regex.Matches(sString, @"(.*?)", RegexOptions.Singleline);`? – Wiktor Stribiżew Nov 22 '16 at 21:39
  • 3
    Why use regex when yo ucan the value of the with the agility pack ? – mybirthname Nov 22 '16 at 21:42
  • @mybirthname because its the first time I am using it. I would love to but that far that I got with it is already too much for me atm. It's easier for me to work with string that html. I would love if you could show me an example though. Thank you both for the help – John P. Nov 22 '16 at 21:55
  • 2
    @JohnP. just google some examples if you have problems you can answer another question. I don't know your context to give you proper example. `var result = doc.DocumentNode.SelectNodes("b");` this will take all b nodes in your document. – mybirthname Nov 22 '16 at 22:01

1 Answers1

4

You need to specify the SingleLine flag to ignore newline characters and escape the forward slash.

MatchCollection matches = Regex.Matches(sString, @"<b>(.*)<\/b>", RegexOptions.Singleline);

See: https://regex101.com/r/zK1vG9/1

Dan Wilson
  • 3,639
  • 2
  • 14
  • 26