1

If I have a few strings:

str = "This is a cool string (orch. details here): 2. Denied."
str2 = " (Orch. details here)" <--notice the capital letter

and then I do this line of code to try to clear that part out:

str3 = Regex.Replace(str, str2, "", RegexOptions.IgnoreCase);

str3 ends up being exactly as what str was before execution. I suspect that it is not "seeing" the other characters such as the periods because when I do this with just simple alphabetic characters in str and str2 then it will replace it just fine.

What gives?! :)

Thank you for any insight!

0

1 Answer 1

5

Both parens and periods have meanings in regular expressions. Hence it's not trying to literally match the contents of str2 but instead a regular expression that is defined by str2. If you want it to match literally you need to escape the string

str2 = Regex.Escape(str2);
Sign up to request clarification or add additional context in comments.

1 Comment

JaredPar, thank you so much, man! That worked like a charm. I am going to go research it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.