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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "<EventID>4702<\\/EventID>|<TimeCreated SystemTime='[^']+'\\/>|<Computer>[^<]+<\\/Computer>|<Data Name='[^']+'>[^<]+<\\/Data>:"; final String string = "<Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'><System><Provider Name='Microsoft-Windows-Security-Auditing' Guid='{54849625-5478-4994-a5ba-3e3b0328c30d}'/><EventID>4702</EventID><Version>1</Version><Level>0</Level><Task>12804</Task><Opcode>0</Opcode><Keywords>0x8020000000000000</Keywords><TimeCreated SystemTime='2024-12-05T14:59:44.9923272Z'/><EventRecordID>2470365</EventRecordID><Correlation ActivityID='{625186de-46eb-0000-1689-5162eb46db01}'/><Execution ProcessID='1408' ThreadID='1600'/><Channel>Security</Channel><Computer>Host</Computer><Security/></System><EventData><Data Name='SubjectUserSid'>S-1-5-20</Data><Data Name='SubjectUserName'> Host $</Data><Data Name='SubjectDomainName'> Host </Data><Data Name='SubjectLogonId'>0x3e4</Data><Data Name='TaskName'>\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask</Data><Data Name='TaskContentNew'>&lt;?xml version=\"1.0\" encoding=\"UTF-16\"?&gt;\n" + "&lt;Task version=\"1.6\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\"&gt;\n" + "&lt;RegistrationInfo&gt;\n" + "&lt;Source&gt;$(@%systemroot%\\system32\\sppc.dll,-200)&lt;/Source&gt;\n" + "&lt;Author&gt;$(@%systemroot%\\system32\\sppc.dll,-200)&lt;/Author&gt;\n" + "&lt;Version&gt;1.0&lt;/Version&gt;\n" + "&lt;Description&gt;$(@%systemroot%\\system32\\sppc.dll,-201)&lt;/Description&gt;\n" + "&lt;URI&gt;\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask&lt;/URI&gt;\n" + "&lt;SecurityDescriptor&gt;D:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)(A;;FR;;;S-1-5-87-2912274048-3994893941-1669128114-1310430903-1263774323)&lt;/SecurityDescriptor&gt;\n" + "&lt;/RegistrationInfo&gt;\n" + "&lt;Triggers&gt;\n" + "&lt;CalendarTrigger&gt;\n" + "&lt;StartBoundary&gt;2024-12-10T07:54:44Z&lt;/StartBoundary&gt;\n" + "&lt;Enabled&gt;true&lt;/Enabled&gt;\n" + "&lt;ScheduleByDay&gt;\n" + "&lt;DaysInterval&gt;1&lt;/DaysInterval&gt;\n" + "&lt;/ScheduleByDay&gt;\n" + "&lt;/CalendarTrigger&gt;\n" + "&lt;/Triggers&gt;\n" + "&lt;Principals&gt;\n" + "&lt;Principal id=\"NetworkService\"&gt;\n" + "&lt;UserId&gt;S-1-5-20&lt;/UserId&gt;\n" + "&lt;RunLevel&gt;LeastPrivilege&lt;/RunLevel&gt;\n" + "&lt;/Principal&gt;\n" + "&lt;/Principals&gt;\n" + "&lt;Settings&gt;\n" + "&lt;MultipleInstancesPolicy&gt;IgnoreNew&lt;/MultipleInstancesPolicy&gt;\n" + "&lt;DisallowStartIfOnBatteries&gt;true&lt;/DisallowStartIfOnBatteries&gt;\n" + "&lt;StopIfGoingOnBatteries&gt;true&lt;/StopIfGoingOnBatteries&gt;\n" + "&lt;AllowHardTerminate&gt;false&lt;/AllowHardTerminate&gt;\n" + "&lt;StartWhenAvailable&gt;true&lt;/StartWhenAvailable&gt;\n" + "&lt;RunOnlyIfNetworkAvailable&gt;false&lt;/RunOnlyIfNetworkAvailable&gt;\n" + "&lt;IdleSettings&gt;\n" + "&lt;StopOnIdleEnd&gt;true&lt;/StopOnIdleEnd&gt;\n" + "&lt;RestartOnIdle&gt;false&lt;/RestartOnIdle&gt;\n" + "&lt;/IdleSettings&gt;\n" + "&lt;AllowStartOnDemand&gt;true&lt;/AllowStartOnDemand&gt;\n" + "&lt;Enabled&gt;true&lt;/Enabled&gt;\n" + "&lt;Hidden&gt;true&lt;/Hidden&gt;\n" + "&lt;RunOnlyIfIdle&gt;false&lt;/RunOnlyIfIdle&gt;\n" + "&lt;DisallowStartOnRemoteAppSession&gt;false&lt;/DisallowStartOnRemoteAppSession&gt;\n" + "&lt;UseUnifiedSchedulingEngine&gt;true&lt;/UseUnifiedSchedulingEngine&gt;\n" + "&lt;WakeToRun&gt;false&lt;/WakeToRun&gt;\n" + "&lt;ExecutionTimeLimit&gt;PT0S&lt;/ExecutionTimeLimit&gt;\n" + "&lt;Priority&gt;7&lt;/Priority&gt;\n" + "&lt;RestartOnFailure&gt;\n" + "&lt;Interval&gt;PT1M&lt;/Interval&gt;\n" + "&lt;Count&gt;3&lt;/Count&gt;\n" + "&lt;/RestartOnFailure&gt;\n" + "&lt;/Settings&gt;\n" + "&lt;Actions Context=\"NetworkService\"&gt;\n" + "&lt;ComHandler&gt;\n" + "&lt;ClassId&gt;{B1AEBB5D-EAD9-4476-B375-9C3ED9F32AFC}&lt;/ClassId&gt;\n" + "&lt;Data&gt;&lt;![CDATA[timer]]&gt;&lt;/Data&gt;\n" + "&lt;/ComHandler&gt;\n" + "&lt;/Actions&gt;\n" + "&lt;/Task&gt;</Data><Data Name='ClientProcessStartKey'>26177172834095606</Data><Data Name='ClientProcessId'>2408</Data><Data Name='ParentProcessId'>1368</Data><Data Name='RpcCallClientLocality'>0</Data><Data Name='FQDN'>Host</Data></EventData></Event>"; 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