Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The regex I use doesn't allow symbols

Tags:

c#

regex

regex = new Regex("(" + str1 + ")", RegexOptions.IgnoreCase);                    

I use this regular expressions to search the text with ignore case and substrings. But when I I give symbols as input, I am getting a ArgumentInvalid exception. How can I allow this to search for symbols also? I am using this expression in C#.Net

like image 816
muthu prakash Avatar asked Dec 14 '25 09:12

muthu prakash


1 Answers

You need to escape the regex.

Use Regex.Escape

like image 69
leppie Avatar answered Dec 17 '25 00:12

leppie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!