Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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# 如果字符串包含单词X,请仅选择单词Y_C#_Regex - Fatal编程技术网

C# 如果字符串包含单词X,请仅选择单词Y

C# 如果字符串包含单词X,请仅选择单词Y,c#,regex,C#,Regex,我有一个类似的问题,我能够解决 我需要的是,如果字符串包含单词X,请仅选择单词Y 我想说,如果这个字符串包含“azureStorage”,那么选择“mystorage” 将查找限制为仅限于字符串azureStorage,然后抓取AccountName=后面不是的任何内容: (?<=azureStorage).*AccountName=([^;]+) 如果需要.NET正则表达式,为什么要使用regex101?regex101不支持.NET语法和功能。在regexhero.net或regex

我有一个类似的问题,我能够解决

我需要的是,如果字符串包含单词X,请仅选择单词Y

我想说,如果这个字符串包含“azureStorage”,那么选择“mystorage”


将查找限制为仅限于字符串
azureStorage
,然后抓取
AccountName=
后面不是
的任何内容

(?<=azureStorage).*AccountName=([^;]+)

如果需要.NET正则表达式,为什么要使用regex101?regex101不支持.NET语法和功能。在regexhero.net或regexstorm.net进行测试。与其使用正则表达式,为什么不解析XML,然后解析连接字符串?为什么不使用
azureStorage.*AccountName=([^;]*)
和抓取捕获的组#1Related:这与@anubhava的答案一起,仅仅访问捕获的组对我来说是可行的。juharr在解析XML方面有一个很好的答案,但我发布的XML字符串只是一个示例,我想知道如何对任何文本进行解析。谢谢
(?<=(azureStorage)...................................................AccountName=).[^;]*
(?<=azureStorage).*AccountName=([^;]+)
(?<=azureStorage).*AccountName=([^;]+)\b