c#求一正则表达式
<li>
<a href="javascript:playMovie('https://media.microsoftstore.jp/product/GFC-02412_JP_Win_7_Hm_Prem_VUP_SP1/Module/JP_Win7_1.wmv');"><img src="https://media.microsoftstore.jp/product/GFC-02412_JP_Win_7_Hm_Prem_VUP_SP1/Module/JP_Win7_video_1.png" width="121" height="77"></a>
</li>
<p id="DMbtnnavi_V1" style="display:block;">
<a href="#" onclick="playMovie('https://media.microsoftstore.jp/product/GFC-02412_JP_Win_7_Hm_Prem_VUP_SP1/Module/JP_Win7_6.wmv'); DM_btn_navi_V(6); return false;">< 前</a>|
<a href="#" onclick="playMovie('https://media.microsoftstore.jp/product/GFC-02412_JP_Win_7_Hm_Prem_VUP_SP1/Module/JP_Win7_2.wmv'); DM_btn_navi_V(2); return false;">次 ></a>
</p>
这上面只是一部分代码 现在想用正则表达式获取
()里面的路径
------解决方案--------------------public static IList<string> GetPicPath(string M_Content)
{
IList<string> im = new List<string>();//定义一个泛型字符类
Regex reg = new Regex(@"(?is)<li>地\s*址:(?<name>.+?)</li>");
MatchCollection mc = reg.Matches(M_Content); //设定要查找的字符串
foreach(Match m in mc)
{
im.Add(m.Groups["name"].Value);
}
return im;
}
------解决方案--------------------如果你是直接把这堆代码拿来处理获得()里的内容的话 直接整个字符串Str.Substring(Str.IndexOf('(') + 1, Str.IndexOf(')') - Str.IndexOf('('));获得就可以了,如果有多对(),你就把处理过的从Str里移除,
------解决方案--------------------
C# code
string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));
string pattern = @"(?i)\((['""])([^'"")]+)\1\)";
foreach (Match m in Regex.Matches(tempStr, pattern))
{
//循环输出
string href = m.Groups[2].Value;
/*
https://media.microsoftstore.jp/product/GFC-02412_JP_Win_7_Hm_Prem_VUP_SP1/Module/JP_Win7_1.wmv
https://media.microsoftstore.jp/product/GFC-02412_JP_Win_7_Hm_Prem_VUP_SP1/Module/JP_Win7_6.wmv
https://media.microsoftstore.jp/product/GFC-02412_JP_Win_7_Hm_Prem_VUP_SP1/Module/JP_Win7_2.wmv
*/
}