首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

正则表达式中间的部分不会写?解决方案

2012-04-04 
正则表达式中间的部分不会写?br /strongLanguage: /strong中间是我想要的东西/p/td/tr请问这

正则表达式中间的部分不会写?
<br /><strong>Language:&nbsp;</strong>中间是我想要的东西</p></td></tr>

请问这个正则表达式怎么写?

其中:“中间是我想要的东西”这部分的字符串长度不确定,有可能是英文字母,数字和空格。

[解决办法]

C# code
            Regex re = new Regex(@"<strong>Language:[\s\S]*?</strong>([\s\S]*?)</p>", RegexOptions.IgnoreCase);            MatchCollection matches = re.Matches(str);            foreach(Match match in matches)            {                Console.WriteLine(match.Groups[1].Value);            }
[解决办法]
C# code
        string s = @"<br /><strong>Language:&nbsp;</strong>中间是我想要的东西</p></td></tr>";        Match match = Regex.Match(s, @"(?is)<strong>.*?</strong>(.+?)</p></td>");        Response.Write(match.Groups[1].Value); 

热点排行