Skip to content

RegEx trouble - need help matching a string

Tom Stephenson

Asked Apr 24, 2006, 2:15 PM EDT1 answer
Share
LinkedInX
Hi there, I am passing a selected area of text as a string (from an IDE text editor) and attempting to match it against a textfile using the following regex : Regex targetExpOld = new Regex(@"^\s+"+content+ @"\s+$", RegexOptions.Multiline); if content = "int i = 6;" i get a match however if content contains a "." or a "(" it doesnt find a match any idea how i can dodge this - i realise its a problem with special characters but I'm new to regex and dont have time to become an expert!(just yet) kind regards Tom

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • +1
    if you have a Regex Expression with Regex metachars you can must escape them:

    string str = Regex.Escape("sdfsd(sdf{sdf*");

    becomes "sdfsd\(sdf\{ etc.
    +1