Is there a way to escape the special characters in regex, such as []()*
and others, from a string?
Basically, I'm asking the user to input a string, and I want to be able to search in the database using regex. Some of the issues I ran into are too many)'s
or [x-y] range in reverse order
, etc.
So what I want to do is write a function to do replace on the user input. For example, replacing (
with (
, replacing [
with [
Is there a built-in function for regex to do so? And if I have to write a function from scratch, is there a way to account all characters easily instead of writing the replace statement one by one?
I'm writing my program in C# using Visual Studio 2010
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…