Home  >  Article  >  Web Front-end  >  Example analysis of using regular expressions to match a tags in js and C#_javascript skills

Example analysis of using regular expressions to match a tags in js and C#_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:30:121572browse

废话不多说,都在代码中,直接上

JS代码:

复制代码 代码如下:








C#代码:

复制代码 代码如下:

string html = "

文字http://bbs.cn.yimg.com/user_img/200701/31/soso1.jpg" mce_href="cchttp://bbs.cn.yimg.com/user_img/200701/31/jisuanji986_117025184198149.jpg">cc> href="www.baidu.com" cbas cchref  1http://bbs.cn.yimg.com/user_img/200701/31/soso2.jpg" mce_href="http://bbs.cn.yimg.com/user_img/200701/31/cc.jpg">>";
Regex reg = new Regex("] [\s] )href=("(?[^<>"']*)"|'(?[^<>"']*)')[^<>]*>", RegexOptions.IgnoreCase);
MatchCollection matchCollection = reg.Matches(html);
MessageBox.Show(matchCollection.Count.ToString());
foreach (Match match in matchCollection)
{
    MessageBox.Show(match.Groups["href"].ToString());
}

小伙伴们是否了解了js及C#中使用正则表达式的异同点呢?有疑问的请留言,大家共同讨论。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn