Regular Expressions 101

Save & Share

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