Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

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 = "^<134> CEF:0\\|(?<product>[^|]+)\\|(?<subproduct>[^|]+)\\|(?<otro>[^|]+)\\|(?<category>[^|]+)\\|(?<subcategory>[^|]+)\\|(?<numero>[^|]+)\\|cs3=\\s(?<cs3>\\w+)\\sSessStart=\\s(?<SessStart>\\w+)\\sSessEnd=\\s(?<SessEnd>\\w+)\\scs4=\\s+sproc=\\s\\\\(?<sproc>[^\\s]+)\\sSessProcID2=\\s+filePath=\\s\\\\(?<filepath>[^\\s]+)\\sAncesProcID=\\s+src=\\s(?<src>[^\\s]+)\\sc6a2=\\s(?<c6a2>[^\\s]+)\\ssourceDnsDomain=\\s+CurrDir=\\s+dst=\\s+dhost=\\s+(?<dhost>[^\\s]+)\\scs2=\\s(?<cs2>[^\\s]+)\\s(?<destinationDnsDomain>[^\\s]+)\\s+deviceCustomDate1=\\s(?<deviceCustomDate1>\\w+\\-\\w+\\-\\w+\\s\\d+\\:\\d+\\:\\d+\\.\\d+)\\srt=\\s(?<rt>\\w+\\-\\w+\\-\\w+\\s\\d+\\:\\d+\\:\\d+\\.\\d+)\\sexternalId=\\s(?<externalId>[^\\s]+)\\scn1=\\s"; final String string = "<134> CEF:0|XYPRO|NONSTOP|XMA|SOFTWARE-NORM-MSGS|SAFEGUARD-NORMAL-MESSAGES|2|cs3= FFFF02F289FAAE5EE62A SessStart= N SessEnd= N cs4= sproc= \\PROKIO.$Z7H3 SessProcID2= filePath= \\PROKIO.$SYSTEM.SYS02.TACL AncesProcID= src= 127.0.0.1 c6a2= 127.0.0.1 sourceDnsDomain= CurrDir= dst= dhost= \\PROKIO\n" + "cs2= $SYSTEM.SAFE destinationDnsDomain= deviceCustomDate1= 2020-12-04 18:42:32.462813 rt= 2020-12-04 12:42:32.462813 externalId= 000000002 cn1= 1 cs6= N / N cn2= 1 Alerted= A deviceFacility= SAFEGUARD suid= 000 , 000 duid= 255 , 143 suser= 000.000 (does not exist) shost= \\PROKIO duser= SUPER.JANAVARR fileType= USER fname= SUPER.JANAVARR 255.143 act= VERIFYUSER cs5= \\PROKIO.$ZTN9.#PT44JMU cat= 54 reason= 400 cs1= msg= Logon Fail count 1 to 0 cn1Label=Outcomecn2Label=XMA_Severitycs1Label=Rulenamecs2Label=ProductLocationcs3Label=SessionIDcs4Label=SessionNamecs5Label=Terminalcs6Label=Test/WarndeviceCustomDate1Label=RecordGMTc6a2Label=SessionIP"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (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