Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • 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 = '/1_ (?<Chapter_1>[^<]*)\n<(?<Benefit>[^<]*)>(?>.*\n)+\s*2_ ([^<]*)\n<(?<IfNotPerform>[^<]*)>[^.*\n+]\s*3_ (?<Chapter_3>[^<]*)\n<(?<ImplSteps>[^<]*)>.*\n+\s* 4_ (?<Chapter_4>[^<]*)\n<(?<AffOpco>[^<]*)>(?>.*\n)+\s*5_ (?<Chapter_5>[^<]*)\n<(?<AffServices>[^<]*)>.*\n+\s*6_ (?<Chapter_6>[^<]*)\n<(?<ServiceImpact>[^<]*)>(?>.*\n)+\s* 7_ (?<Chapter_7>[^<]*)\n<(?<Risks>[^<]*)>.*\n+\s*8_ (?<Chapter_8>[^<]*)\n<(?<PreImplTest>[^<]*)>.*\n+\s*9_ (?<Chapter_9>[^<]*)\n<(?<AfterImplTest>[^<]*)>.*\n+\s* 11_ (?<Chapter_11>[^<]*)\n<(?<Fallback>[^<]*)>.*\n+\s*12_ (?<Chapter_12>[^<]*)\n<(?<AffCI>[^<]*)>.*\n+\s*13_ (?<Chapter_13>[^<]*)\n<(?<AffDC>[^<]*)>.*\n+\s* 15_ (?<Chapter_15>[^<]*)\n<(?<WithinMW>[^<]*)>.*\n+\s*19_ (?<Chapter_19>[^<]*)\n<(?<SAF>[^<]*)>.*\n+\s*20_ (?<Chapter_20>[^<]*)\n<(?<Rollback>[^<]*)>(?>.*\n)+\s*43_(?<Chapter_43>[^<]*)\n<(?<Impact>[^<]*)>/m'; $str = ' ************************************************************** - MANDATORY FOR ALL CHANGES - ************************************************************** 1_ Motivation / Benefit / Reason for change (Describe the Motivation, the benefit out of this change/ what will the change achieve/ what is the trigger/driver of this change) <...> 2_ What will happen if Change not performed (Describe the risk of not implementing the change) <...> 3_ Change Scenario / detailed Implementation Steps (Describe the change in a non-technical language/what will be changed) <...> 4_ Affected OpCo/customers (Please use: All Customers/None/Name of customer) <...> 5_ Affected Services (List services which will be affected by the change: Data, IITC, SMS, Voice, Provisioning, M2M Portal, NB-IoT, B2C Portal, SOBE, API, Reporting, Billing, SMPP, Device Management, Customer Feature, WEB Service GUI, LBAS, C-IoT) <...> 6_ Describe the SERVICE IMPACT eg: any outages to Infrastructure hardware or temporary loss of service? (Describe the EXPECTED SERVICE IMPACT, during change implementation, including duration: Service Affecting activity? Service Outage / Service Degradation /if there is no impact then mention why.) <...> 7_ Describe the RISKS during implementation/ what could go wrong? And add the worst case scenario. (What will the customer face if the something goes wrong during execution (Worst case scenario). If there is no risk then mention why.) <...> 8_ Pre-Implementation Tests/previous examples (Please choose one of the following Test results evidences and provide the needed info, PLEASE COPY AND PAST YOUR CHOICE IN THE TRIANGLE BRACKETS: a- Change has been performed before with same scenario successfully, CRQ examples: ... b- Test document will be attached in work info [Y/N/NA]?: ... c- Pilot testing was performed with users in Prod [Y/N/NA]?: ... d- Test results can\'t be provided because: ....) <...> 9_ Test Scenario after change (Brief Description regarding the list of activities which will be done when the change is completed) <...> 11_ Fallback Scenario (Describe briefly what will be done in case of rollback) <...> 12_ Affected Configuration Items (CIs/Components as: CSDB/GDSP/IITC/GCSDB/GGSN) <...> 13_ Affected Data Centers (Or Location: SPE1, SPE2, etc.) <...> 15_ Within maintenance window (Y/N, Why?) (If the change is out of the agreed Maintenance Window, please specifiy why) <...> 19_ SAF [Y/N] (Is the Activity Service Affecting [Y/N]) <...> 20_ Rollback outage [Y/N] (Is there a downtime during Rollback? If yes, mention the duration) <...> 22_ Fallback details (in UTC) 22a_ <Rollback Start: DD/MM/YYYY HH:MM> 22b_ <Rollback End: DD/MM/YYYY HH:MM>" 40_ Change implementer (Group name, Operation Engineer Name & Email & contact number) <...> 41_ VBPS Validation/SLS MDS engineer for VBPS changes (Who validated the change?) <...> 42_ Capability Manager (Who reviewed the change for Level4) <...> 43_Anything impacted? [Y/N] <...> --- End of required information --- *** Please Fill out *** '; 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