[英]How to extract a quoted string using regular expression? OR How to use this particular regular expression (“[^”]*\.csv") in c#?
[英]Using regular expression on string for use in C#
我正在嘗試從字符串中提取 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:”之后。 我不是正則表達式方面的專家,我所能做的就是:
imgurl:'(.*)',tid
whiitch 在一些在線正則表達式測試器上工作。 但不是我在 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 數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.