Qual è l'equivalente di PHP preg_quote?Qual è l'equivalente del preg_quote di PHP?
Questo è quanto ho ottenuto per la creazione di un metodo che estrae il testo da una stringa:
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 è vicino ma sembra comportarsi in modo leggermente diverso in alcuni scenari. In particolare, non sfugge "]" caratteri che possono o non possono essere un problema. –