PHP的preg_quote相当于什么?

时间:2012-02-10 21:49:34

标签: c#

PHP的preg_quote等同于什么?

这是我创建一个从字符串中提取文本的方法:

    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;
    }

3 个答案:

答案 0 :(得分:7)

答案 1 :(得分:0)

在C#中没有preg_quote的直接替换,但你可以编写自己的函数来做到这一点。从PHP手册中,函数转义的字符是:. \ + * ? [ ^ ] $ ( ) { } = ! < > | : -所以你只需编写一个带字符串的函数,并转义任何这些字符。

答案 2 :(得分:0)

您在寻找Regex.Escape吗?