什么是PHP的preg_quote的等价物?什么是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;
}
Regex.Escape很接近,但在某些情况下它似乎略有不同。特别是,它不会逃避可能成为问题或可能不成问题的“]”字符。 – 2012-02-10 21:59:58