DTE dte = Package.GetGlobalService(typeof(DTE))作为DTE; TextDocument activeDoc = dte.ActiveDocument.Object()as TextDocument;
var text = activeDoc.CreateEditPoint(activeDoc.StartPoint).GetText(activeDoc.EndPoint);
var input = (text);
var regex = new Regex(@"(\bresourcekey\b+) = ");
var match = regex.Matches(input);
string matches = string.Empty;
foreach(var item in match)
{
matches += item.ToString() + " ";
}
MessageBox.Show(matches);
我的正则表达式命令出错(我知道),但是我想从我的消息框文本中捕获meta:resourcekey =“ ......”,我只希望....是捕获的一部分。
答案 0 :(得分:0)
这里是纯正则表达式
meta:resourcekey [\ s] = [\ s] \“(。*?)\”
这是c#示例
var mydata = "meta:resourcekey = \"something\"";
Regex regex = new Regex("meta:resourcekey[\\s]*=[\\s]*\"(.*?)\\\"");
foreach (Match htmlPath in regex.Matches(mydata))
{
Console.WriteLine(htmlPath.Groups[1].Value);
}
答案 1 :(得分:0)
DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;
TextDocument activeDoc = dte.ActiveDocument.Object() as TextDocument;
var text = activeDoc.CreateEditPoint(activeDoc.StartPoint).GetText(activeDoc.EndPoint);
var input = (text);
Regex regex = new Regex(@"(meta:resourcekey)+(\W)+(\w*)+(\W)");
var match = regex.Matches(input);
string matches = string.Empty;
foreach(var item in match)
{
matches += item.ToString() + " ";
}
MessageBox.Show(matches);
我找到了这样的答案。这使Scann成为当前页面代码并写入文本,最后得到meta:resourcekey =“ something”所有代码页...写入MessageBox