How to do regular expressions / regex in Visual Basic?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to do regular expressions / regex in Visual Basic?

    The Regex() method is in the System.Text.RegularExpressions namespace.

    An example using regular expressions is below:

    Code:
    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            Dim URLPath As String = Request.Url.AbsolutePath()
            If Regex.IsMatch(URLPath, "(?i:^/eNlight-Howtos.aspx$)") Or Regex.IsMatch(URLPath, "(?i:^/Login.aspx$)") Or Regex.IsMatch(URLPath, "(?i:^/Submit-Howtos.aspx$)") Then
                ContactUsPanel.Visible = False
            End If
        End Sub
    The regular expression is the second parameter of the IsMatch() method. The brackets around the regular expression is required because of the ?i: modifier, which essentially ignores case sensitivity (so eNlight-Howtos.aspx and enlight-howtos.aspx would still be returned as TRUE).

    Other resources
    Regular Expressions: What are they and how do I use them? | Official Web Hosting Blog by eUKhost Ltd.
Working...
X