John P. John P. - 1 year ago 173
C# Question

Regex get string between two strings

I am using

to get some classes and then from the
of the classes I want to get a collection of a

My string looks like this:

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

Answer Source

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);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download