Avatar of dba123
dba123

asked on 

Unrecognized escape sequence error in my Regex method

I'm getting an "unrecognized escape sequence error", mostly likely I think because of my quotes.  I'm not sure how to escape the quotes properly here:

MatchCollection mc = Regex.Matches(ProductDescription,"<a href=\"ProductInfo\.aspx\?ProductID=([\d]+)\">(sss|here)</a>");
C#

Avatar of undefined
Last Comment
dba123
Avatar of Brett Crawley
Brett Crawley

You need a double backslash infront of the ? and the . because they were to escape the . and ? in the regex not in the C#. I should have pointed this out earlier. Sorry about that.

If you put a double backslash C# will escape the second backslash with the first allowing it to go in the string
Avatar of Brett Crawley
Brett Crawley

Your quotes are fine
Avatar of dba123
dba123

ASKER

thanks.  I tried this but it is still complaining

<a href=\"ProductInfo\\.aspx\\?ProductID=([\d]+)\">(WAV|here)</a>

also tried:

<a href=\"ProductInfo\.\aspx\?\ProductID=([\d]+)\">(WAV|here)</a>
ASKER CERTIFIED SOLUTION
Avatar of Brett Crawley
Brett Crawley

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dba123
dba123

ASKER

thanks!
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo