Catching \n\r with RegEx

I have the following multi-line text:

</td></tr><tr><td align="left"

There is a hex 0d0a after span> and before </td>

This is my Regex expression (which is not working)...

r2 = new Regex(@"</b><br></span>\\r\\n</td></tr><tr><td align=""left""");

Can someone please tell me why it won't recognize the CRLF?  I've tried it with \\n\\r also (I'm a bit confused as to what the 0d0a means as far as /n and /r)

Thank you in advance... :D
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Could you try [\\r\\n]+? I've got that in my regexs and it seems to work. Of course you can then narrow it down with a range {1, 2} instead of + later on.

Looking again - I think you might also be having problem with the < and > characters - can you try escaping those to \\< and \\>

What are you using the regex in? Is it with a regex object in code?
lol: when I say "Could you try [\\r\\n]+?" I don't mean you should include the question mark - sorry!

And you can forget my last "I'm with stupid" question about "is it with ..."

I think you should try:

r2 = new Regex(@"\</b\>\<br\>\</span\>[\r\n]+\</td\>\</t\d>\<tr\>\<td align=""left""");

Note that if you are using @ before your string, you don't need to escape the backslashes.

Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

ugh, my typing sucks:

r2 = new Regex(@"\</b\>\<br\>\</span\>[\r\n]+\</td\>\</td\>\<tr\>\<td align=""left""");

(corrected "/t\d>" to "/td\>")

Sorry for the email spam :-)
rmmarshAuthor Commented:
Normally I have no problems with the < and >... it's just that this is multi-line text and the /n/r is giving me a fit... don't know if /n is a 0x0a or a 0x0d and that's part of the problem... the other part of the problem is that the RegEx expression is wrong, but I can't see it...

Tried both of your ideas, and it still fails... again, I don't think it's the < or >

Hello rmmarsh,

tried your sample html from above in a richtextbox and some code like

string Msg = richTextBox1.Text;  

//when i looked at Msg here it showed a \n as linefeed character

// and after some experimentation this expression matched the above
Match expr = Regex.Match(Msg, @"</b><br></span>\n</td></tr><tr><td align=""left""");


so i don't know if this resembles your setup but i didn't need to escape \n so it could work for you with a clean \r\n

hope this helps a bit

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rmmarshAuthor Commented:
Thank you so much, bruintje... that worked...

Hmm, sorry about that. How are you testing your regex? Have you tried developing it in something like Expresso ( and then moving it into code?

AFAIK, \r is a carriage return, which is ascii 13, and so is 0x0d, and \n is a line feed character, so is ascii 10, which is 0x0d. So you are definately using the right characters.

You are right about the < and > I don't know where I got that particular sock to smoke (all of my regex just became a lot simpler so thank _you_).

If i do simply:
r2 = new Regex(@"</b><br></span>\r\n</td></tr><tr><td align=""left""");
with the regex options
Ignore case, MultiLine (no others) then it succesfully captures text from a text file with your text in.

Can you try
r2 = new Regex(@".\r\n.");
and see if it captures the ">\r\n<" part? It does in my test case.

Glad you got it to work, but I'm a little confused as if you have 0x0d0x0a then you definitely have \r\n and not just \n. Never mind, as long as it works in your code ...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.