Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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/4/regex/16.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/2/node.js/41.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#_Regex - Fatal编程技术网

C# 正则表达式匹配动态模式

C# 正则表达式匹配动态模式,c#,regex,C#,Regex,我需要使用Regex(或Match)解析一个字符串: SomeTextHereThatIWantToIgnore:“或SomeTextHereThatIWantToIgnore:” 可能有一个、两个或三个字符串(都在一行上)需要解析。在每种情况下,我都需要获取“”之间的所有内容 因此,在第一个示例中,我想获取“first Month.104.yyy-mm-dd”和“Last Day.2.yyy-mm-dd”。在第二个示例中,我想获取“BadVerb.104” 任何可以向我展示如何实现这一点的正

我需要使用Regex(或Match)解析一个字符串:

SomeTextHereThatIWantToIgnore:“或SomeTextHereThatIWantToIgnore:”
可能有一个、两个或三个字符串(都在一行上)需要解析。在每种情况下,我都需要获取“”之间的所有内容

因此,在第一个示例中,我想获取“first Month.104.yyy-mm-dd”和“Last Day.2.yyy-mm-dd”。在第二个示例中,我想获取“BadVerb.104”

任何可以向我展示如何实现这一点的正则表达式大师?

您可以使用以下方法(使用
s
修饰符进行多行匹配):


(?s)(?试试:
[\s\s]*

[\s\s]捕获任何空白字符或任何非空白字符,因此它们将一起捕获
之间的任何内容


请参见

获取尖括号内文本而不捕获括号的基本正则表达式是

(?<=<)[^>]+(?=>)

谢谢Stribizev,我不知道Matches系列。我最后做了一个简单的模式:

[<]([^>]+)
[]+)
也就是说,查找一个“”。matches集合就是我要查找的部分。我迭代了Match集合,并能够进一步解析结果字符串并获得我想要的内容


感谢安德烈·萨米,Karthik和Walker(那个看起来也很简单)。

伟大,那么请考虑接受和支持我的答案,因为它对你有用。这个正则表达式基本上是相同的,但是没有用放置<代码>。
(?<=<)[^>]+(?=>)
var matches = Regex.Matches(str, @"(?<=<)[^>]+(?=>)");
[<]([^>]+)