Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
gm

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(\bPublic Class AddressVerification\b)|(\bEnd Class\b)"; string input = @" Public Class AddressVerification Public SingleAddress As Boolean Public Address As Address Public Addresses As List(Of Address) Public Sub New(Optional singleAddress As Boolean = False) Me.SingleAddress = singleAddress If Not singleAddress Then Addresses = New List(Of Address)() Else Address = New Address() End If End Sub End Class Public Class Address Public ClientId As String Public PrimaryLine As String Public SecondaryLine As String Public City As String Public State As String Public ZipCode As String End Class Public Class Remits Public UserId As String Public Letters As List(Of Letter) Public Sub New() Letters = New List(Of Letter)() End Sub End Class Public Class Letter Public ClientId As String Public CustomerId As String End Class ====================== C:\Users\Avell\Documents\workingfolder\M3\src\M3.WebSite\customerservice\aging\clientdocumentsedit.aspx.vb Public Class LobTrackEvent Public Id As String Public Name As String Public Location As String Public Time As DateTime <JsonProperty(""date_created"")> Public Created As DateTime <JsonProperty(""date_modified"")> Public Modified As DateTime End Class ====================== C:\Users\Avell\Documents\workingfolder\M3\src\M3.WebSite\customerservice\customerremitnoa\clientinformationedit.aspx.vb Public Class AddressVerificationResponse <JsonProperty(""id"")> Public Id As String <JsonProperty(""recipient"")> Public Recipient As String <JsonProperty(""primary_line"")> Public PrimaryLine As String <JsonProperty(""secondary_line"")> Public SecondaryLine As String <JsonProperty(""urbanization"")> Public Urbanization As String <JsonProperty(""last_line"")> Public LastLine As String <JsonProperty(""deliverability"")> Public Deliverability As String <JsonProperty(""components"")> Public Components As Components <JsonProperty(""deliverability_analysis"")> Public DeliverabilityAnalysis As DeliverabilityAnalysis <JsonProperty(""object"")> Public StrObject As String End Class Public Class Components <JsonProperty(""primary_number"")> Public PrimaryNumber As String <JsonProperty(""street_predirection"")> Public StreetPredirection As String <JsonProperty(""street_name"")> Public StreetName As String <JsonProperty(""street_suffix"")> Public StreetSuffix As String <JsonProperty(""street_postdirection"")> Public StreetPostdirection As String <JsonProperty(""secondary_designator"")> Public SecondaryDesignator As String <JsonProperty(""secondary_number"")> Public SecondaryNumber As String <JsonProperty(""pmb_designator"")> Public PmbDesignator As String <JsonProperty(""pmb_number"")> Public PmbNumber As String <JsonProperty(""extra_secondary_information"")> Public ExtraSecondaryInformation As String <JsonProperty(""city"")> Public City As String <JsonProperty(""state"")> Public State As String <JsonProperty(""zip_code"")> Public ZipCode As String <JsonProperty(""zip_code_plus_4"")> Public ZipCodePlus4 As String <JsonProperty(""zip_code_type"")> Public ZipCodeType As String <JsonProperty(""delivery_point_barcode"")> Public DeliveryPointBarcode As String <JsonProperty(""address_type"")> Public AddressType As String <JsonProperty(""record_type"")> Public RecordType As String <JsonProperty(""default_building_address"")> Public DefaultBuildingAddress As Boolean <JsonProperty(""county"")> Public County As String <JsonProperty(""county_fips"")> Public CountyFips As String <JsonProperty(""carrier_route"")> Public CarrierRoute As String <JsonProperty(""carrier_route_type"")> Public CarrierRouteType As String <JsonProperty(""latitude"")> Public Latitude As Object <JsonProperty(""longitude"")> Public Longitude As Object End Class Public Class DeliverabilityAnalysis <JsonProperty(""dpv_confirmation"")> Public DpvConfirmation As String <JsonProperty(""dpv_cmra"")> Public DpvCmra As String <JsonProperty(""dpv_vacant"")> Public DpvVacant As String <JsonProperty(""dpv_footnotes"")> Public DpvFootnotes As Object() <JsonProperty(""ews_match"")> Public EwsMatch As Boolean <JsonProperty(""lacs_indicator"")> Public LacsIndicator As String <JsonProperty(""lacs_return_code"")> Public LacsReturnCode As String <JsonProperty(""suite_return_code"")> Public SuiteReturnCode As String End Class <Serializable> Public Class LegalAddressVerification Private serviceAggrementValue As Boolean Public Property ServiceAggrement() As Boolean Get Return serviceAggrementValue End Get Set(ByVal value As Boolean) serviceAggrementValue = value End Set End Property Private serviceAggrementUserValue As String Public Property ServiceAggrementUser() As String Get Return serviceAggrementUserValue End Get Set(ByVal value As String) serviceAggrementUserValue = value End Set End Property Private serviceAggrementDateValue As DateTime Public Property ServiceAggrementDate() As DateTime Get Return serviceAggrementDateValue End Get Set(ByVal value As DateTime) serviceAggrementDateValue = value End Set End Property Private creditReportValue As Boolean Public Property CreditReport() As Boolean Get Return creditReportValue End Get Set(ByVal value As Boolean) creditReportValue = value End Set End Property Private creaditReportUserValue As String Public Property CreditReportUser() As String Get Return creaditReportUserValue End Get Set(ByVal value As String) creaditReportUserValue = value End Set End Property Private creditReportDateValue As DateTime Public Property CreditReportDate() As DateTime Get Return creditReportDateValue End Get Set(ByVal value As DateTime) creditReportDateValue = value End Set End Property Private invoiceValue As Boolean Public Property Invoice() As Boolean Get Return invoiceValue End Get Set(ByVal value As Boolean) invoiceValue = value End Set End Property Private invoiceUserValue As String Public Property InvoiceUser() As String Get Return invoiceUserValue End Get Set(ByVal value As String) invoiceUserValue = value End Set End Property Private invoiceDateValue As DateTime Public Property InvoiceDate() As DateTime Get Return invoiceDateValue End Get Set(ByVal value As DateTime) invoiceDateValue = value End Set End Property Private secretaryStateValue As Boolean Public Property SecretaryState() As Boolean Get Return secretaryStateValue End Get Set(ByVal value As Boolean) secretaryStateValue = value End Set End Property Private secretaryStateUserValue As String Public Property SecretaryStateUser() As String Get Return secretaryStateUserValue End Get Set(ByVal value As String) secretaryStateUserValue = value End Set End Property Private secretaryStateDateValue As DateTime Public Property SecretaryStateDate() As DateTime Get Return secretaryStateDateValue End Get Set(ByVal value As DateTime) secretaryStateDateValue = value End Set End Property End Class ======================= C:\Users\Avell\Documents\workingfolder\M3\src\M3.WebSite\customerservice\customerremitnoa\generateletter.aspx.vb Class RequestBody Public ContactName As String Public ContactEmail As String Public File As String Public SignatureRequestId As String End Class "; RegexOptions options = RegexOptions.Multiline; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx