Regular Expressions 101

Save & Share

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

/
/

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "<\\d+>\\S+\\s(\\d{4}-\\d{2}-\\d{2})\\s(\\d{2}\\x3a\\d{2}\\x3a\\d{2}),\\d+\\s\\x5b\\d+\\x5d\\s+\\S+\\s+\\S+\\s\\S+\\s+\\S+\\s+\\S+\\s\\S+\\s\\ServerIPAddress\\x3a\\s\\S+\\s((?:\\d{1,3}\\x2e){3}\\d{1,3})\\s+ClientIPAddress\\x3a\\s(\\S+)\\s\\S+\\s\\S+\\s\\S+\\s\\S+\\s+\\S+\\s\\S+\\s+\\S+\\s\\S+\\s+\\S+\\s\\S+\\s+\\S+\\s+\\S+\\s+MessageText\\x3a\\s(Admin\\sActivity)\\s+UserId\\x3a\\s(\\d+)\\s+UserName\\x3a\\s(\\S+)\\s+Action\\sDate\\/Time\\x3a\\s+\\S+\\s\\S+\\s\\S+\\s+Portal\\sGroup\\sId\\x3a\\s(\\d+)\\s+Portal Group Name\\x3a\\s([a-zA-Z\\s]+)\\s+Action\\sType\\x3a\\s([a-zA-Z\\s]+)\\sAction\\sDetail\\x3a([a-zA-Z0-9\\.\\;\\s\\:]+)\\sArea\\sOf\\sAdministration\\x3a\\s(\\S+)\\s+Portal\\sId\\x3a\\s(\\d+)\\s+Portal\\sName\\x3a\\s([a-zA-Z0-9\\s]+)\\s+Enterprise\\sUser\\x3a\\s(\\S+)"; final String string = "<190>MedSeekBusinessServer.exe: 2016-08-08 09:04:06,965 [4] INFO MedSeek.Portal.Server.LoggingProvider.Data.AuditTrailSqlDao UserID: -9999 UserName: System ServerIPAddress: 10.247.82.26 10.247.82.112 ClientIPAddress: (null) PortalId: (null) PortalName: (null) AssemblyName: MedSeek.Portal.Server.LoggingProvider\n" + " ClassName: AuditTrailSqlDao\n" + " MethodName: LogToSysLog\n" + " CustomProps: 6ZalfDCycQw=\n" + " MessageText: Admin Activity\n" + " UserId: 301640\n" + " UserName: myost6\n" + " Action Date/Time: 8/8/2016 1:04:06 PM\n" + " Portal Group Id: 1273153\n" + " Portal Group Name: myCarolinas Admin\n" + " Action Type: Update User\n" + " Action Detail: User updated. User ID: 301640; UserName: myost6; \n" + " Area Of Administration: Users\n" + " Portal Id: 6\n" + " Portal Name: my Carolinas Mobile\n" + " Enterprise User: False\n" + "<190>MedSeekBusinessServer.exe: 2016-08-08 09:04:06,965 [4] INFO MedSeek.Portal.Server.LoggingProvider.Data.AuditTrailSqlDao UserID: -9999 UserName: System ServerIPAddress: 10.247.82.26 10.247.82.112 ClientIPAddress: (null) PortalId: (null) PortalName: (null) AssemblyName: MedSeek.Portal.Server.LoggingProvider\n" + " ClassName: AuditTrailSqlDao\n" + " MethodName: LogToSysLog\n" + " CustomProps: 6ZalfDCycQw=\n" + " MessageText: Admin Activity\n" + " UserId: 301640\n" + " UserName: myost6\n" + " Action Date/Time: 8/8/2016 1:04:06 PM\n" + " Portal Group Id: 1273153\n" + " Portal Group Name: myCarolinas Admin\n" + " Action Type: Update User\n" + " Action Detail: User updated. User ID: 301640; UserName: myost6; \n" + " Area Of Administration: Users\n" + " Portal Id: 6\n" + " Portal Name: my Carolinas Mobile\n" + " Enterprise User: False \n" + "<190>MedSeekBusinessServer.exe: 2016-08-08 09:04:12,815 [4] INFO MedSeek.Portal.Server.LoggingProvider.Data.AuditTrailSqlDao UserID: -9999 UserName: System ServerIPAddress: 10.247.82.26 10.247.82.112 ClientIPAddress: (null) PortalId: (null) PortalName: (null) AssemblyName: MedSeek.Portal.Server.LoggingProvider\n" + " ClassName: AuditTrailSqlDao\n" + " MethodName: LogToSysLog\n" + " CustomProps: 6ZalfDCycQw=\n" + " MessageText: Admin Activity\n" + " UserId: 244010\n" + " UserName: katdbod\n" + " Action Date/Time: 8/8/2016 1:04:12 PM\n" + " Portal Group Id: 1273153\n" + " Portal Group Name: myCarolinas Admin\n" + " Action Type: Update User\n" + " Action Detail: User updated. User ID: 244010; UserName: katdbod; \n" + " Area Of Administration: Users\n" + " Portal Id: 2\n" + " Portal Name: myCarolinas\n" + " Enterprise User: False\n" + "<190>MedSeekBusinessServer.exe: 2016-08-08 09:04:12,815 [4] INFO MedSeek.Portal.Server.LoggingProvider.Data.AuditTrailSqlDao UserID: -9999 UserName: System ServerIPAddress: 10.247.82.26 10.247.82.112 ClientIPAddress: (null) PortalId: (null) PortalName: (null) AssemblyName: MedSeek.Portal.Server.LoggingProvider%0D ClassName: AuditTrailSqlDao%0D MethodName: LogToSysLog%0D CustomProps: 6ZalfDCycQw=%0D MessageText: Admin Activity%0D UserId: 244010%0D UserName: katdbod%0D Action Date/Time: 8/8/2016 1:04:12 PM%0D Portal Group Id: 1273153%0D Portal Group Name: myCarolinas Admin%0D Action Type: Update User%0D Action Detail: User updated. User ID: 244010; UserName: katdbod; %0D Area Of Administration: Users%0D Portal Id: 2%0D Portal Name: myCarolinas%0D Enterprise User: False%0D \n" + "<190>MedSeekBusinessServer.exe: 2016-08-08 09:04:12,971 [4] INFO MedSeek.Portal.Server.LoggingProvider.Data.AuditTrailSqlDao UserID: -9999 UserName: System ServerIPAddress: 10.247.82.26 10.247.82.112 ClientIPAddress: (null) PortalId: (null) PortalName: (null) AssemblyName: MedSeek.Portal.Server.LoggingProvider%0D ClassName: AuditTrailSqlDao%0D MethodName: LogToSysLog%0D CustomProps: 6ZalfDCycQw=%0D MessageText: Admin Activity%0D UserId: 244010%0D UserName: katdbod%0D Action Date/Time: 8/8/2016 1:04:12 PM%0D Portal Group Id: 1273153%0D Portal Group Name: myCarolinas Admin%0D Action Type: Update User%0D Action Detail: User updated. User ID: 244010; UserName: katdbod; %0D Area Of Administration: Users%0D Portal Id: 2%0D Portal Name: myCarolinas%0D Enterprise User: False%0D \n" + "<190>MedSeekBusinessServer.exe: 2016-08-08 09:04:12,971 [4] INFO MedSeek.Portal.Server.LoggingProvider.Data.AuditTrailSqlDao UserID: -9999 UserName: System ServerIPAddress: 10.247.82.26 10.247.82.112 ClientIPAddress: (null) PortalId: (null) PortalName: (null) AssemblyName: MedSeek.Portal.Server.LoggingProvider%0D ClassName: AuditTrailSqlDao%0D MethodName: LogToSysLog%0D CustomProps: 6ZalfDCycQw=%0D MessageText: Admin Activity%0D UserId: 244010%0D UserName: katdbod%0D Action Date/Time: 8/8/2016 1:04:12 PM%0D Portal Group Id: 1273153%0D Portal Group Name: myCarolinas Admin%0D Action Type: Update User%0D Action Detail: User updated. User ID: 244010; UserName: katdbod; %0D Area Of Administration: Users%0D Portal Id: 2%0D Portal Name: myCarolinas%0D Enterprise User: False%0D \n" + "<190>MedSeekBusinessServer.exe: 2016-08-08 09:04:33,766 [4] INFO MedSeek.Portal.Server.LoggingProvider.Data.AuditTrailSqlDao UserID: -9999 UserName: System ServerIPAddress: 10.247.82.26 10.247.82.112 ClientIPAddress: (null) PortalId: (null) PortalName: (null) AssemblyName: MedSeek.Portal.Server.LoggingProvider%0D ClassName: AuditTrailSqlDao%0D MethodName: LogToSysLog%0D CustomProps: 6ZalfDCycQw=%0D MessageText: Admin Activity%0D UserId: 164664%0D UserName: rrrleigh%0D Action Date/Time: 8/8/2016 1:04:33 PM%0D Portal Group Id: 1273153%0D Portal Group Name: myCarolinas Admin%0D Action Type: Change User Password%0D Action Detail: Password changed for user. User ID: 164664; %0D Area Of Administration: Users%0D Portal Id: 2%0D Portal Name: myCarolinas%0D Enterprise User: False%0D \n" + "<190>MedSeekBusinessServer.exe: 2016-08-08 09:04:33,766 [4] INFO MedSeek.Portal.Server.LoggingProvider.Data.AuditTrailSqlDao UserID: -9999 UserName: System ServerIPAddress: 10.247.82.26 10.247.82.112 ClientIPAddress: (null) PortalId: (null) PortalName: (null) AssemblyName: MedSeek.Portal.Server.LoggingProvider%0D ClassName: AuditTrailSqlDao%0D MethodName: LogToSysLog%0D CustomProps: 6ZalfDCycQw=%0D MessageText: Admin Activity%0D UserId: 164664%0D UserName: rrrleigh%0D Action Date/Time: 8/8/2016 1:04:33 PM%0D Portal Group Id: 1273153%0D Portal Group Name: myCarolinas Admin%0D Action Type: Change User Password%0D Action Detail: Password changed for user. User ID: 164664; %0D Area Of Administration: Users%0D Portal Id: 2%0D Portal Name: myCarolinas%0D Enterprise User: False%0D \n"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); if (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html