-2

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 = "......" 我只想要 .... 我捕获的一部分。

4

2 回答 2

0

这是普通的正则表达式

元: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);
}
于 2018-07-18T08:30:41.670 回答
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);

我找到了这样的答案。这使得扫描当前页面代码并写入文本,最后得到 meta:resourcekey="something" 所有代码页......写入 MessageBox

于 2018-07-18T11:05:20.210 回答