Sideway
output.to from Sideway
Draft for Information Only

Content

Regular Expression Miscellaneous Constructs
  .NET Miscellaneous Constructs
   Inline Options
   Inline Comment
   End-of-Line Comment
 Examples
 See also
 Source/Referencee

Regular Expression Miscellaneous Constructs

Regular expressions in .NET include three miscellaneous language constructs. One lets you enable or disable particular matching options in the middle of a regular expression pattern. The remaining two let you include comments in a regular expression.

.NET Miscellaneous Constructs

Inline Options

You can set or disable specific pattern matching options for part of a regular expression by using the syntax

(?imnsx-imnsx)

You list the options you want to enable after the question mark, and the options you want to disable after the minus sign. The following table describes each option. For more information about each option, see Regular Expression Options.

Option Description
i Case-insensitive matching.
m Multiline mode.
n Explicit captures only. (Parentheses do not act as capturing groups.)
s Single-line mode.
x Ignore unescaped white space, and allow x-mode comments.

Any change in regular expression options defined by the (?imnsx-imnsx) construct remains in effect until the end of the enclosing group.

The (?imnsx-imnsx:subexpression) grouping construct provides identical functionality for a subexpression. For more information, see Grouping Constructs.

Inline Comment

The (?# comment) construct lets you include an inline comment in a regular expression. The regular expression engine does not use any part of the comment in pattern matching, although the comment is included in the string that is returned by the Regex.ToString method. The comment ends at the first closing parenthesis.

End-of-Line Comment

A number sign (#)marks an x-mode comment, which starts at the unescaped # character at the end of the regular expression pattern and continues until the end of the line. To use this construct, you must either enable the x option (through inline options) or supply the RegexOptions.IgnorePatternWhitespace value to the option parameter when instantiating the Regex object or calling a static Regex method.

Note that, instead of providing the (?x) construct in the regular expression, the comment could also have been recognized by calling the Regex.IsMatch(String, String, RegexOptions) method and passing it the RegexOptions.IgnorePatternWhitespace enumeration value.

Examples

Examples of Miscellaneous Constructs
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 = "zabcd fg ijaab"
               Dim xmatchstr As String = ""
               xmatchstr = xmatchstr & "Given string: """ & xstring & """<br />"
               xmatchstr = xmatchstr & showresult(xstring,"(?i)(\w)(\w).+F")
               xmatchstr = xmatchstr & showresult(xstring,"((?#comment)\w)(\w).+f")
               xmatchstr = xmatchstr & showresult(xstring,"(?x)(\w)(\w).+ # comment")
               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,"<","&lt;") & """): """
               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 Miscellaneous Constructs</h1>") %>
       <p>
           <%-- Set on Page_Load --%>
           <asp:Label id="lbl01" runat="server" />
       </p>
    </body>
</html>
HTML Web Page Embedded Output:

See also

  • Regular Expression Language - Quick Reference

Source/Referencee

  • https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference
  • https://docs.microsoft.com/en-us/dotnet/standard/base-types/miscellaneous-constructs-in-regular-expressions

©sideway

ID: 190800003 Last Updated: 3/8/2019 Revision: 0 Ref:

close

References

  1. Active Server Pages,  
  2. ASP Overview,  
  3. ASP Best Practices,  
  4. ASP Built-in Objects,  
  5. Response Object,  
  6. Request Object,  
  7. Server Object (IIS),  
  8. Application Object (IIS),  
  9. Session Object (IIS),  
  10. ASPError Object,  
  11. ObjectContext Object (IIS),  
  12. Debugging Global.asa Files,  
  13. How to: Debug Global.asa files,  
  14. Calling COM Components from ASP Pages,  
  15. IIS ASP Scripting Reference,  
  16. ASP Keywords,  
  17. Creating Simple ASP Pages,  
  18. Including Files in ASP Applications,  
  19. ASP Overview,  
  20. FileSystemObject Object,  
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  
  22. ADO Fundamentals,  
close
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 7

Culture

Chinese 1097

English 337

Reference 67

Computer

Hardware 149

Software

Application 187

Digitization 24

Numeric 19

Programming

Web 740

CSS 1

ASP.NET 1

Regular Expression 1

HTML

Knowledge Base

Common Color 1

Html Entity (Unicode) 1

Html 401 Special 1

OS 389

MS Windows

Windows10 1

.NET Framework 1

DeskTop 7

Knowledge

Mathematics

Formulas 8

Algebra 20

Number Theory 206

Trigonometry 18

Geometry 18

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Physics

Electric 5

Biology 1

Geography 1


Copyright © 2000-2019 Sideway . All rights reserved Disclaimers last modified on 06 September 2019