假设有一行"link ="- direct "C:/directory/";我试图使用正则表达式来获取"C:/directory"C:/directory
Regex p = new Regex(""([^"]+)"");
string dirs = p.Match(link).Value;
,但是dirs字符串返回带引号的字符串"C:/directory"
,这里需要纠正正则表达式,使字符串不带引号
var link = "- direct "C:/directory/"";
var p = new System.Text.RegularExpressions.Regex(@"-s*directs*""([^""]+)""");
var result = p.Match(link).Groups[1].Value;
System.Console.WriteLine(result);
未检测到引号:)您使用了"()"因此,result显示为一个组数组,其中第一个元素是完全匹配,第二个元素是()中的匹配。