Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 生成正则表达式以查找具有以下条件的字符串_C#_Asp.net_Regex_C# 4.0_Office Interop - Fatal编程技术网

C# 生成正则表达式以查找具有以下条件的字符串

C# 生成正则表达式以查找具有以下条件的字符串,c#,asp.net,regex,c#-4.0,office-interop,C#,Asp.net,Regex,C# 4.0,Office Interop,请向我推荐以下字符串的正则表达式模式: 我必须使用Microsoft.Office.Interop.Word查找这些字符串,然后将搜索字符串保存在数据库中 感谢您提供的帮助。有一个答案,请告诉我是否正确: <[^/>]*> ]*> 试试这个: private Regex angleReg = new Regex(@"<([^>]+)>\s+<([^>]+)>"); private string[] parse(string rawInp

请向我推荐以下字符串的正则表达式模式:

我必须使用Microsoft.Office.Interop.Word查找这些字符串,然后将搜索字符串保存在数据库中


感谢您提供的帮助。

有一个答案,请告诉我是否正确:

<[^/>]*>
]*>
试试这个:

private Regex angleReg = new Regex(@"<([^>]+)>\s+<([^>]+)>");

private string[] parse(string rawInput)
{
    Match angleMatch = angleReg.Match(rawInput);

    if (angleMatch.Success)
    {
        return new string[] { angleMatch.Groups[1].Value, angleMatch.Groups[2].Value };
    }
    else
    {
        return null;
    }
}
private Regex angleReg=new Regex(@“]+)>\s++>”;
私有字符串[]解析(字符串输入)
{
匹配angleMatch=angleReg.Match(原始输入);
如果(angleMatch.Success)
{
返回新字符串[]{angleMatch.Groups[1]。值,angleMatch.Groups[2]。值};
}
其他的
{
返回null;
}
}

在.NET正则表达式中,类似于
[^abcd]
的东西意味着“任何不是a、b、c或d的东西”,所以在我们的例子中,我们想要任何不是“>”的东西
[^>]+
表示“任何未>的内容”“一次或多次”,这就是
+
的含义。因此,
a+
匹配“a”、“aa”、“aaa”等。
(x)(y)
匹配“xy”,但在您的匹配对象中,.Groups列表将包含
组[1]
处的“x”和
组[2]
处的“y”,以便轻松访问匹配的字符串。

有一秒钟,我以为您是在尝试使用正则表达式的新手,因此,他感到困惑,并要求帮助。谢谢大家,就是这样。美好的