Tanpa mengatakan banyak omong kosong, itu semua dalam kode, cukup unggah
Kode JS:
Salinan kode adalah sebagai berikut:
<Html>
<head>
<bahasa skrip = "javascript">
var a = '<p> <a href =/' ~ abc/ccg/ab.jpg/'> teks </a> <a style = "color: #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 </a> </a> href = "www.baidu.com" cbas </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"> </p9;
var b =/<a ([/s]+| [/s]+[^<>]+[/s]+) href = (/"([^<>"/']*)/"|/' ([^<>"/']*)/') [^<>]*>/gi;
var s = a.tolowercase (). kecocokan (b);
peringatan (s.length);
untuk (var i = 0; i <s.length; i ++)
{
var ss = s [i] .tolowercase (). Match (b);
peringatan (regexp. $ 3+regexp. $ 4);
}
</script>
</head>
<body>
</body>
</html>
Kode C#:
Salinan kode adalah sebagai berikut:
String html = "<p> <a href = '~ abc/ccg/ab.jpg' height =/" 4/"width = '3'> teks </a> <a width =/" 4/"style =/" color: #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/" href =/"cc/" <a lebar =/"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 = Regex baru ("<a ([// s]+| [// s]+[^<>]+[// s]+) href = (/" (? <href> [^<>/"']*)/" |' (? <href> [^<>/"']*)') [^]", ", <> <>/" ')') ')') [^] ").
MatchCollection MatchCollection = reg.matches (html);
MessageBox.Show (MatchCollection.Count.ToString ());
foreach (pertandingan pertandingan dalam pertandingan pertandingan)
{
MessageBox.Show (Match.groups ["href"]. ToString ());
}
Sudahkah Anda memahami persamaan dan perbedaan menggunakan ekspresi reguler di JS dan C#? Jika Anda memiliki pertanyaan, silakan tinggalkan pesan dan diskusikan bersama.