What is equivalent to PHP preg_quote?

What is the equivalent of PHP preg_quote ?

This is how much I got to create a method that extracts text from a string:

    public static string f_get_string_between(string text, string start, string end)
    {
        //both these attempts below throw an unrecognized escape sequence error
        //start = "\Q"+start+"\E";
        //end = "\Q"+end+"\E"; 

        Regex regex = new Regex(start + "(.*?)" + end);
        var v = regex.Match(text);
        text = v.Groups[1].ToString();
        return text;
    }
+5
source share
3 answers
+7
source

There is no direct replacement in C # preg_quote, but you can write your own function to do just that. From the PHP manual, the characters that exit the function are as follows: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -so you just write a function that takes a string and avoids any of these characters.

0
source

Are you looking for Regex.Escape ?

0
source

All Articles