Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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中使用#_C#_.net_Regex - Fatal编程技术网

C# 在字符串上使用正则表达式以在C中使用#

C# 在字符串上使用正则表达式以在C中使用#,c#,.net,regex,C#,.net,Regex,我正在尝试从字符串中提取url {ns:"images",k:"5127",mid:"A04F21EB77CF61E10E43BA33CF1986CA44357448" ,md5:"e2987d19c953bd836ec8fd2e0aa8492",surl:"http://someURLIdontwant/" ,imgurl:"http://THISISTHEURLINEED.jpg",tid:"OIP.Me2987d199c953bd836ec8fd2e0aa8492H0" ,ow:"300"

我正在尝试从字符串中提取url

{ns:"images",k:"5127",mid:"A04F21EB77CF61E10E43BA33CF1986CA44357448"
,md5:"e2987d19c953bd836ec8fd2e0aa8492",surl:"http://someURLIdontwant/"
,imgurl:"http://THISISTHEURLINEED.jpg",tid:"OIP.Me2987d199c953bd836ec8fd2e0aa8492H0"
,ow:"300", docid:"608010036892077154",oh:"225",tft:"49"}
所以它位于“imgurl:”之后。我不是Regex方面的专家,我能做的就是:

imgurl:'(.*)',tid
whitch在某个在线正则表达式测试仪上工作。但显然不是我在C#中使用它的方式

webClient.DownloadFile(System.Text.RegularExpressions.Regex.Match
(stringWithText, "imgurl:'(.*)',tid").Groups[1].Value,"path\file.jpg");

能做到吗?正如@WiktorStribiżew已经指出的那样,谢谢你:这个表达几乎是正确的。改用这个:

Regex.Match(stringWithText, "imgurl:\"(.*)\",tid").Groups[1].Value


正如我在前面的一篇评论中提到的:您应该解析Json数据。

字符串中有双引号,模式中有单撇号。这些数据就是Json。使用Json解析器将其反序列化为直接访问
imgurl
。请看用正则表达式解析嵌套结构(HTML/XML/JSON)充其量是非常困难的-请查看指南并在下面搜索更多类似的答案。啊,该死的。感觉离我很近,但又很远。谢谢你的帮助!