Sans dire beaucoup de bêtises, tout est dans le code, il suffit de le télécharger
Code js:
La copie de code est la suivante:
<html>
<adal>
<script linguisse = "javascript">
var a = '<p> <a href = /' ~ abc / ccg / ab.jpg / '> text </a> <a style = "couleur: #ddd; font-weight: bold;" mm_href = "http: www.baidu.com" href = "http://bbs.cn.yimg.com/user_img/200701/31/soso1.jpg" mce_href = "http://bbs.cn.yimg.com/user_img/200701/31/jisuanji986_117025184198149.jpg"> cc </a> <A href = "http://bbs.cn.yimg.com/user_img/200701/31/soso2.jpg" mce_href = "http://bbs.cn.yimg.com/user_img/200701/31/cc.jpg"> </a> </200701/31/cc.jpg "> </a> </200701/31/cc.jpg"> </a> </ P> ';
var b = / <a ([/ s] + | [/ s] + [^ <>] + [/ s] +) href = (/ "([^ <>" / '] *) / "| /' ([^ <>" / '] *) /') [^ <>] *> / gi;
var s = a.tolowercase (). Match (b);
alerte (S.Length);
pour (var i = 0; i <s.length; i ++)
{
var ss = s [i] .tolowerCase (). Match (b);
alerte (regexp. 3 $ + regexp. 4 $);
}
</cript>
</ head>
<body>
</docy>
</html>
C # Code:
La copie de code est la suivante:
String html = "<p> <a href = '~ abc / ccg / ab.jpg' height = /" 4 / "width = '3'> text </a> <a width = /" 4 / "style = /" couleur: #ddd; FONT-WEIGHT: Bold; / "mm_href = /" http: www.baidu.com/ "href = /" http://bbs.cn.yimg.com/user_img/200701/31/soso1.jpg/ " mce_href = / "http://bbs.cn.yimg.com/user_img/200701/31/jisuanji986_117025184198149.jpg/"> cc </a> href = / "www.baidu.com/" cbas <pandi href = / "cc /" <a width = / "5 /" href = / "http://bbs.cn.yimg.com/user_img/200701/31/soso2.jpg/" mce_href = / "http://bbs.cn.yimg.com/user_img/200701/31/cc.jpg/"> </a> </p> ";
Regex reg = new regex ("<a ([// s] + | [// s] + [^ <>] + [// s] +) href = (/" (? <Href> [^ <> / "'] *) /" |' (? <href> [^ <> / "'] *)') [^ <>] *>", regexoptions.ignorecase);
MatchCollection MatchCollection = reg.matches (html);
MessageBox.show (matchCollection.Count.ToString ());
foreach (match de match dans MatchCollection)
{
MessageBox.show (Match.Groups ["HREF"]. ToString ());
}
Avez-vous compris les similitudes et les différences d'utilisation des expressions régulières dans JS et C #? Si vous avez des questions, veuillez laisser un message et discuter ensemble.