Regular Expression Examples Scanning For HREFs Scanning For Date Format Scanning For Protocol And Port Number Scanning Of Invalid Characters Scanning of Valid Email Format See also Source/Referencee
Regular Expression Examples
Scanning For HREFs
Examples Of Scanning For HREFs
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script runat="server">
Sub Page_Load()
Dim xstring As String = "<A HREF=""http://msd4n2.m4icr44.com"">"
Dim xmatchstr As String = ""
xmatchstr = xmatchstr & "Given string: """ & Replace(xstring,"<","<") & """<br />"
xmatchstr = xmatchstr & showresult(xstring,"(?i)href\s*=\s*(?:[""'](?<1>[^""']*)[""']|(?<1>\S+))")
lbl01.Text = xmatchstr
End Sub
Function showresult(xstring,xpattern)
Dim xmatch As Match
Dim xcaptures As CaptureCollection
Dim ycaptures As CaptureCollection
Dim xgroups As GroupCollection
Dim xmatchstr As String = ""
Dim xint As Integer
Dim yint As Integer
Dim zint As Integer
xmatchstr = xmatchstr & "<br />Result of Regex.Match(string,""" & Replace(xpattern,"<","<") & """): """
xmatch = Regex.Match(xstring,xpattern)
xmatchstr = xmatchstr & xmatch.value & """<br />"
xcaptures = xmatch.Captures
xmatchstr = xmatchstr & "->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & xcaptures.Count & """<br />"
For xint = 0 to xcaptures.Count - 1
xmatchstr = xmatchstr & "->->Result of CaptureCollection("& xint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xcaptures(xint).Value & ", " & xcaptures(xint).Index & ", " & xcaptures(xint).Length & """<br />"
xgroups = xmatch.Groups
xmatchstr = xmatchstr & "->Result of GroupCollection.Count: """
xmatchstr = xmatchstr & xgroups.Count & """<br />"
For yint = 0 to xgroups.Count - 1
xmatchstr = xmatchstr & "->->Result of GroupCollection("& yint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xgroups(yint).Value & ", " & xgroups(yint).Index & ", " & xgroups(yint).Length & """<br />"
ycaptures = xgroups(yint).Captures
xmatchstr = xmatchstr & "->->->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & ycaptures.Count & """<br />"
For zint = 0 to ycaptures.Count - 1
xmatchstr = xmatchstr & "->->->->Result of CaptureCollection("& zint & ").Value, Index, Length: """
xmatchstr = xmatchstr & ycaptures(zint).Value & ", " & ycaptures(zint).Index & ", " & ycaptures(zint).Length & """<br />"
Next
Next
Next
Return xmatchstr
End Function
</script>
</head>
<body>
<% Response.Write ("<h1>This is a Sample Page of Scanning for HREFs</h1>") %>
<p>
<%-- Set on Page_Load --%>
<asp:Label id="lbl01" runat="server" />
</p>
</body>
</html>
HTML Web Page Embedded Output:
Scanning For Date Format
Examples Of Scanning For Date Format
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script runat="server">
Sub Page_Load()
Dim xstring As String = "12/12/26"
Dim xmatchstr As String = ""
xmatchstr = xmatchstr & "Given string: """ & Replace(xstring,"<","<") & """<br />"
xmatchstr = xmatchstr & showresult(xstring,"\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b")
lbl01.Text = xmatchstr
End Sub
Function showresult(xstring,xpattern)
Dim xmatch As Match
Dim xcaptures As CaptureCollection
Dim ycaptures As CaptureCollection
Dim xgroups As GroupCollection
Dim xmatchstr As String = ""
Dim xint As Integer
Dim yint As Integer
Dim zint As Integer
xmatchstr = xmatchstr & "<br />Result of Regex.Match(string,""" & Replace(xpattern,"<","<") & """): """
xmatch = Regex.Match(xstring,xpattern)
xmatchstr = xmatchstr & xmatch.value & """<br />"
xcaptures = xmatch.Captures
xmatchstr = xmatchstr & "->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & xcaptures.Count & """<br />"
For xint = 0 to xcaptures.Count - 1
xmatchstr = xmatchstr & "->->Result of CaptureCollection("& xint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xcaptures(xint).Value & ", " & xcaptures(xint).Index & ", " & xcaptures(xint).Length & """<br />"
xgroups = xmatch.Groups
xmatchstr = xmatchstr & "->Result of GroupCollection.Count: """
xmatchstr = xmatchstr & xgroups.Count & """<br />"
For yint = 0 to xgroups.Count - 1
xmatchstr = xmatchstr & "->->Result of GroupCollection("& yint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xgroups(yint).Value & ", " & xgroups(yint).Index & ", " & xgroups(yint).Length & """<br />"
ycaptures = xgroups(yint).Captures
xmatchstr = xmatchstr & "->->->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & ycaptures.Count & """<br />"
For zint = 0 to ycaptures.Count - 1
xmatchstr = xmatchstr & "->->->->Result of CaptureCollection("& zint & ").Value, Index, Length: """
xmatchstr = xmatchstr & ycaptures(zint).Value & ", " & ycaptures(zint).Index & ", " & ycaptures(zint).Length & """<br />"
Next
Next
Next
Return xmatchstr
End Function
</script>
</head>
<body>
<% Response.Write ("<h1>This is a Sample Page of Scanning for Date Format</h1>") %>
<p>
<%-- Set on Page_Load --%>
<asp:Label id="lbl01" runat="server" />
</p>
</body>
</html>
HTML Web Page Embedded Output:
Scanning For Protocol And Port Number
Examples Of Scanning For Protocol And Port Number
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script runat="server">
Sub Page_Load()
Dim xstring As String = "http://www.cl455oso.com:8080/letters/readme.html"
Dim xmatchstr As String = ""
xmatchstr = xmatchstr & "Given string: """ & Replace(xstring,"<","<") & """<br />"
xmatchstr = xmatchstr & showresult(xstring,"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/")
lbl01.Text = xmatchstr
End Sub
Function showresult(xstring,xpattern)
Dim xmatch As Match
Dim xcaptures As CaptureCollection
Dim ycaptures As CaptureCollection
Dim xgroups As GroupCollection
Dim xmatchstr As String = ""
Dim xint As Integer
Dim yint As Integer
Dim zint As Integer
xmatchstr = xmatchstr & "<br />Result of Regex.Match(string,""" & Replace(xpattern,"<","<") & """): """
xmatch = Regex.Match(xstring,xpattern)
xmatchstr = xmatchstr & xmatch.value & """<br />"
xcaptures = xmatch.Captures
xmatchstr = xmatchstr & "->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & xcaptures.Count & """<br />"
For xint = 0 to xcaptures.Count - 1
xmatchstr = xmatchstr & "->->Result of CaptureCollection("& xint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xcaptures(xint).Value & ", " & xcaptures(xint).Index & ", " & xcaptures(xint).Length & """<br />"
xgroups = xmatch.Groups
xmatchstr = xmatchstr & "->Result of GroupCollection.Count: """
xmatchstr = xmatchstr & xgroups.Count & """<br />"
For yint = 0 to xgroups.Count - 1
xmatchstr = xmatchstr & "->->Result of GroupCollection("& yint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xgroups(yint).Value & ", " & xgroups(yint).Index & ", " & xgroups(yint).Length & """<br />"
ycaptures = xgroups(yint).Captures
xmatchstr = xmatchstr & "->->->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & ycaptures.Count & """<br />"
For zint = 0 to ycaptures.Count - 1
xmatchstr = xmatchstr & "->->->->Result of CaptureCollection("& zint & ").Value, Index, Length: """
xmatchstr = xmatchstr & ycaptures(zint).Value & ", " & ycaptures(zint).Index & ", " & ycaptures(zint).Length & """<br />"
Next
Next
Next
Return xmatchstr
End Function
</script>
</head>
<body>
<% Response.Write ("<h1>This is a Sample Page of Scanning for Protocol and Port Number</h1>") %>
<p>
<%-- Set on Page_Load --%>
<asp:Label id="lbl01" runat="server" />
</p>
</body>
</html>
HTML Web Page Embedded Output:
Scanning Of Invalid Characters
Examples Of Scanning out all nonalphanumeric characters except periods (.), at symbols (@), And hyphens (-).
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script runat="server">
Sub Page_Load()
Dim xstring As String = "http://www.cl4@55oso.c.- -om: -8-080/letters/readme.html"
Dim xmatchstr As String = ""
xmatchstr = xmatchstr & "Given string: """ & Replace(xstring,"<","<") & """<br />"
xmatchstr = xmatchstr & showresult(xstring,"((?<invalid>[^\w\.@-]*)(?<valid>[\w\.@-]*))*")
lbl01.Text = xmatchstr
End Sub
Function showresult(xstring,xpattern)
Dim xmatch As Match
Dim xcaptures As CaptureCollection
Dim ycaptures As CaptureCollection
Dim xgroups As GroupCollection
Dim xmatchstr As String = ""
Dim xint As Integer
Dim yint As Integer
Dim zint As Integer
xmatchstr = xmatchstr & "<br />Result of Regex.Match(string,""" & Replace(xpattern,"<","<") & """): """
xmatch = Regex.Match(xstring,xpattern)
xmatchstr = xmatchstr & xmatch.value & """<br />"
xcaptures = xmatch.Captures
xmatchstr = xmatchstr & "->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & xcaptures.Count & """<br />"
For xint = 0 to xcaptures.Count - 1
xmatchstr = xmatchstr & "->->Result of CaptureCollection("& xint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xcaptures(xint).Value & ", " & xcaptures(xint).Index & ", " & xcaptures(xint).Length & """<br />"
xgroups = xmatch.Groups
xmatchstr = xmatchstr & "->Result of GroupCollection.Count: """
xmatchstr = xmatchstr & xgroups.Count & """<br />"
For yint = 0 to xgroups.Count - 1
xmatchstr = xmatchstr & "->->Result of GroupCollection("& yint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xgroups(yint).Value & ", " & xgroups(yint).Index & ", " & xgroups(yint).Length & """<br />"
ycaptures = xgroups(yint).Captures
xmatchstr = xmatchstr & "->->->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & ycaptures.Count & """<br />"
For zint = 0 to ycaptures.Count - 1
xmatchstr = xmatchstr & "->->->->Result of CaptureCollection("& zint & ").Value, Index, Length: """
xmatchstr = xmatchstr & ycaptures(zint).Value & ", " & ycaptures(zint).Index & ", " & ycaptures(zint).Length & """<br />"
Next
Next
Next
Return xmatchstr
End Function
</script>
</head>
<body>
<% Response.Write ("<h1>This is a Sample Page of Scanning of Invalid Characters</h1>") %>
<p>
<%-- Set on Page_Load --%>
<asp:Label id="lbl01" runat="server" />
</p>
</body>
</html>
HTML Web Page Embedded Output:
Scanning of Valid Email Format
Examples of Scanning of Valid Email Format.
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script runat="server">
Sub Page_Load()
Dim xstring As String = "dahhhvid.johgnes@prghjjosehware.com"
Dim xmatchstr As String = ""
xmatchstr = xmatchstr & "Given string: """ & Replace(xstring,"<","<") & """<br />"
xmatchstr = xmatchstr & showresult(xstring,"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`{}|~\w])*)(?<=[0-9a-z])@))(?([)([(\d{1,3}.){3}\d{1,3}])|(([0-9a-z][-0-9a-z]*[0-9a-z]*.)+[a-z0-9][-a-z0-9]{0,22}[a-z0-9]))$")
lbl01.Text = xmatchstr
End Sub
Function showresult(xstring,xpattern)
Dim xmatch As Match
Dim xcaptures As CaptureCollection
Dim ycaptures As CaptureCollection
Dim xgroups As GroupCollection
Dim xmatchstr As String = ""
Dim xint As Integer
Dim yint As Integer
Dim zint As Integer
xmatchstr = xmatchstr & "<br />Result of Regex.Match(string,""" & Replace(xpattern,"<","<") & """): """
xmatch = Regex.Match(xstring,xpattern)
xmatchstr = xmatchstr & xmatch.value & """<br />"
xcaptures = xmatch.Captures
xmatchstr = xmatchstr & "->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & xcaptures.Count & """<br />"
For xint = 0 to xcaptures.Count - 1
xmatchstr = xmatchstr & "->->Result of CaptureCollection("& xint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xcaptures(xint).Value & ", " & xcaptures(xint).Index & ", " & xcaptures(xint).Length & """<br />"
xgroups = xmatch.Groups
xmatchstr = xmatchstr & "->Result of GroupCollection.Count: """
xmatchstr = xmatchstr & xgroups.Count & """<br />"
For yint = 0 to xgroups.Count - 1
xmatchstr = xmatchstr & "->->Result of GroupCollection("& yint & ").Value, Index, Length: """
xmatchstr = xmatchstr & xgroups(yint).Value & ", " & xgroups(yint).Index & ", " & xgroups(yint).Length & """<br />"
ycaptures = xgroups(yint).Captures
xmatchstr = xmatchstr & "->->->Result of CaptureCollection.Count: """
xmatchstr = xmatchstr & ycaptures.Count & """<br />"
For zint = 0 to ycaptures.Count - 1
xmatchstr = xmatchstr & "->->->->Result of CaptureCollection("& zint & ").Value, Index, Length: """
xmatchstr = xmatchstr & ycaptures(zint).Value & ", " & ycaptures(zint).Index & ", " & ycaptures(zint).Length & """<br />"
Next
Next
Next
Return xmatchstr
End Function
</script>
</head>
<body>
<% Response.Write ("<h1>This is a Sample Page of Scanning of of Valid Email Format</h1>") %>
<p>
<%-- Set on Page_Load --%>
<asp:Label id="lbl01" runat="server" />
</p>
</body>
</html>