Regular Expression Thread Safety Scanning of Valid Email Format See also Source/Referencee
Regular Expression Thread Safety
The Regex class itself is thread safe and immutable (read-only). That is, Regex objects can be created on any thread and shared between threads; matching methods can be called from any thread and never alter any global state.
However, result objects (Match and MatchCollection) returned by Regex should be used on a single thread. Although many of these objects are logically immutable, their implementations could delay computation of some results to improve performance, and as a result, callers must serialize access to them.
If there is a need to share Regex result objects on multiple threads, these objects can be converted to thread-safe instances by calling their synchronized methods. With the exception of enumerators, all regular expression classes are thread safe or can be converted into thread-safe objects by a synchronized method.
Enumerators are the only exception. An application must serialize calls to collection enumerators. The rule is that if a collection can be enumerated on more than one thread simultaneously, you should synchronize enumerator methods on the root object of the collection traversed by the enumerator.
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 = ""
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>