If you can't read please download the document
Upload
vodung
View
225
Download
5
Embed Size (px)
Citation preview
- .NET Tips (VB.NET,C#...)
Top > > .NET Tips > HTMLHTML
.NET Framework
RegexMatchMatchsMatch
TextBox1Regular-Expressions.info
VB.NETJavaScript
'Regex Dim r As New System.Text.RegularExpressions.Regex( _ "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", _ System.Text.RegularExpressions.RegexOptions.IgnoreCase)
'TextBox1.Text1 Dim m As System.Text.RegularExpressions.Match = r.Match(TextBox1.Text)
' 'Dim mc As System.Text.RegularExpressions.MatchCollection = _' r.Matches(TextBox1.Text)
While m.Success ' Console.WriteLine(m.Value) ' m = m.NextMatch()End While
C#JavaScript
//RegexSystem.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex( @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
//TextBox1.Text1System.Text.RegularExpressions.Match m = r.Match(TextBox1.Text);
////System.Text.RegularExpressions.MatchCollection mc = r.Matches(TextBox1.Text);
while (m.Success){ // Console.WriteLine(m.Value); // m = m.NextMatch();}
HTML
(?)MatchGroupsMSDNHREFS URL
TextBox1HTMLHH1H2H3...MatchMatchesMatch
VB.NETJavaScript
'Regex Dim r As New System.Text.RegularExpressions.Regex( _ "]*>(.*?)", _ System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _ System.Text.RegularExpressions.RegexOptions.Singleline)
'TextBox1.Text Dim mc As System.Text.RegularExpressions.MatchCollection = _ r.Matches(TextBox1.Text)
For Each m As System.Text.RegularExpressions.Match In mc ' Console.WriteLine(":" + m.Groups(1).Value + vbCrLf + _ ":" + m.Groups(2).Value)Next
C#JavaScript
//RegexSystem.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex( @"]*>(.*?)", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
//TextBox1.TextSystem.Text.RegularExpressions.MatchCollection mc = r.Matches(TextBox1.Text);
foreach (System.Text.RegularExpressions.Match m in mc){ // Console.WriteLine(":" + m.Groups[1].Value + "\n:" + m.Groups[2].Value + "\n:" + m.Groups[1].Index);}
HTML
TextBox1...URLMatchesMatch
VB.NETJavaScript
'TextBox1.Text Dim mc As System.Text.RegularExpressions.MatchCollection = _ System.Text.RegularExpressions.Regex.Matches( _ TextBox1.Text, _ "]*href\s*=\s*(?:(?[""'])(?.*?)\k|" + _ "(?[^\s>]+))[^>]*>(?.*?)", _ System.Text.RegularExpressions.RegexOptions.IgnoreCase Or _ System.Text.RegularExpressions.RegexOptions.Singleline)
For Each m As System.Text.RegularExpressions.Match In mc ' Console.WriteLine("URL:{0}", m.Groups("url").Value) Console.WriteLine(":{0}", m.Groups("text").Value)Next
C#JavaScript
//TextBox1.TextSystem.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches( TextBox1.Text, @"]*href\s*=\s*(?:(?[""'])(?.*?)\k|" + @"(?[^\s>]+))[^>]*>(?.*?)", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
foreach (System.Text.RegularExpressions.Match m in mc){ // Console.WriteLine("URL:{0}", m.Groups["url"].Value); Console.WriteLine(":{0}", m.Groups["text"].Value);}
(\d)+12311233.NET Framework
Captures
(\d)+123
VB.NETJavaScript
Dim r As New System.Text.RegularExpressions.Regex("(\d)+")Dim mc As System.Text.RegularExpressions.MatchCollection = r.Matches("123")
For Each m As System.Text.RegularExpressions.Match In mc For i As Integer = 0 To m.Groups.Count - 1 Console.WriteLine("{0}:{1}", i, m.Groups(i)) For l As Integer = 0 To m.Groups(i).Captures.Count - 1 Console.WriteLine(" {0}:{1}", l, m.Groups(i).Captures(l).Value) Next NextNext
C#JavaScript
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex( @"(\d)+");System.Text.RegularExpressions.MatchCollection mc = r.Matches("123");
foreach (System.Text.RegularExpressions.Match m in mc){ for (int i = 0; i < m.Groups.Count; i++) { Console.WriteLine("{0}:{1}", i, m.Groups[i]); for (int l = 0; l < m.Groups[i].Captures.Count; l++) { Console.WriteLine(" {0}:{1}", l, m.Groups[i].Captures[l].Value); } }}
0:123 0:1231:3 0:1 1:2 2:3
131Captures
2009/5/18 2009/6/20 HTML2009/9/9 HTML
.NET Tips
JavaScript
JavaScript
200%190%180%170%160%150%140%130%120%110%100%90%80%70%60%50%40%30%20%10%
200%190%180%170%160%150%140%130%120%110%100%90%80%70%60%50%40%30%20%10%
VB.NET C#
.NET TipsDataGridView.NET...
Translate
Please enable JavaScript.
WikiDOBON.NET
Copyright(C) DOBON!. All rights reserved.