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

$re = '/<EventID>4702<\/EventID>|<TimeCreated SystemTime=\'[^\']+\'\/>|<Computer>[^<]+<\/Computer>|<Data Name=\'[^\']+\'>[^<]+<\/Data>:/m'; $str = '<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; &lt;Task version="1.6" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"&gt; &lt;RegistrationInfo&gt; &lt;Source&gt;$(@%systemroot%\\system32\\sppc.dll,-200)&lt;/Source&gt; &lt;Author&gt;$(@%systemroot%\\system32\\sppc.dll,-200)&lt;/Author&gt; &lt;Version&gt;1.0&lt;/Version&gt; &lt;Description&gt;$(@%systemroot%\\system32\\sppc.dll,-201)&lt;/Description&gt; &lt;URI&gt;\\Microsoft\\Windows\\SoftwareProtectionPlatform\\SvcRestartTask&lt;/URI&gt; &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; &lt;/RegistrationInfo&gt; &lt;Triggers&gt; &lt;CalendarTrigger&gt; &lt;StartBoundary&gt;2024-12-10T07:54:44Z&lt;/StartBoundary&gt; &lt;Enabled&gt;true&lt;/Enabled&gt; &lt;ScheduleByDay&gt; &lt;DaysInterval&gt;1&lt;/DaysInterval&gt; &lt;/ScheduleByDay&gt; &lt;/CalendarTrigger&gt; &lt;/Triggers&gt; &lt;Principals&gt; &lt;Principal id="NetworkService"&gt; &lt;UserId&gt;S-1-5-20&lt;/UserId&gt; &lt;RunLevel&gt;LeastPrivilege&lt;/RunLevel&gt; &lt;/Principal&gt; &lt;/Principals&gt; &lt;Settings&gt; &lt;MultipleInstancesPolicy&gt;IgnoreNew&lt;/MultipleInstancesPolicy&gt; &lt;DisallowStartIfOnBatteries&gt;true&lt;/DisallowStartIfOnBatteries&gt; &lt;StopIfGoingOnBatteries&gt;true&lt;/StopIfGoingOnBatteries&gt; &lt;AllowHardTerminate&gt;false&lt;/AllowHardTerminate&gt; &lt;StartWhenAvailable&gt;true&lt;/StartWhenAvailable&gt; &lt;RunOnlyIfNetworkAvailable&gt;false&lt;/RunOnlyIfNetworkAvailable&gt; &lt;IdleSettings&gt; &lt;StopOnIdleEnd&gt;true&lt;/StopOnIdleEnd&gt; &lt;RestartOnIdle&gt;false&lt;/RestartOnIdle&gt; &lt;/IdleSettings&gt; &lt;AllowStartOnDemand&gt;true&lt;/AllowStartOnDemand&gt; &lt;Enabled&gt;true&lt;/Enabled&gt; &lt;Hidden&gt;true&lt;/Hidden&gt; &lt;RunOnlyIfIdle&gt;false&lt;/RunOnlyIfIdle&gt; &lt;DisallowStartOnRemoteAppSession&gt;false&lt;/DisallowStartOnRemoteAppSession&gt; &lt;UseUnifiedSchedulingEngine&gt;true&lt;/UseUnifiedSchedulingEngine&gt; &lt;WakeToRun&gt;false&lt;/WakeToRun&gt; &lt;ExecutionTimeLimit&gt;PT0S&lt;/ExecutionTimeLimit&gt; &lt;Priority&gt;7&lt;/Priority&gt; &lt;RestartOnFailure&gt; &lt;Interval&gt;PT1M&lt;/Interval&gt; &lt;Count&gt;3&lt;/Count&gt; &lt;/RestartOnFailure&gt; &lt;/Settings&gt; &lt;Actions Context="NetworkService"&gt; &lt;ComHandler&gt; &lt;ClassId&gt;{B1AEBB5D-EAD9-4476-B375-9C3ED9F32AFC}&lt;/ClassId&gt; &lt;Data&gt;&lt;![CDATA[timer]]&gt;&lt;/Data&gt; &lt;/ComHandler&gt; &lt;/Actions&gt; &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>'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php