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
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 = "EXP.*\\n(?P<data1>[0-9]+)\\n(?P<data2>[0-9]+)\\n(?P<data3>[0-9]+)\\n(?P<gname>[A-z_0-9]+)\\n(?P<gcode>[A-Z]+)\\n(?P<gvers>[0-9]+)\\n(?P<app_desc>[A-z0-9 ]+)\\n(?P<run_desc>[A-z0-9 ]+)\\n(?P<last_mod>[A-z0-9: ]+)\\n(?P<data4>.*)\\n(?P<parent>.*\\.(?:APP|app))\\n(?P<script>.*\\.(?:APP|app))\\n(?P<app_type>[A-Z]+)\\n(?P<app_vpr>.*\\.(?:VPR|vpr))\\n"; final String string = "&PROJFIL\n" + "EXP0 3 0Node File {CATALOG_DIR}\\99_temp\\initial_nodes.dbf \n" + "EXP1 1 0Matrix File 1 {CATALOG_DIR}\\99_temp\\Y{year}_initial_skims.mat \n" + "EXP1 220Network File {CATALOG_DIR}\\99_temp\\initial_highway_loaded.net \n" + "EXP2 1 0Network File {CATALOG_DIR}\\99_temp\\checked_pt_network.net \n" + "EXP2 7 0NTLegs File {SCENARIO_DIR}\\Y{year}_{NetName}_nt_legs.ntl \n" + "EXP2 130Route File 1 {CATALOG_DIR}\\99_temp\\initial_PT_skims.rte \n" + "EXP2 230Matrix File 1 {CATALOG_DIR}\\\\99_temp\\initial_PT_costs.mat \n" + "EXP3 1 0Network File {SCENARIO_DIR}\\Y{year}_unloaded_network.net \n" + "EXP5 210Record File 1 {CATALOG_DIR}\\99_temp\\vc_factors.dbf \n" + "EXP5 220Record File 2 {CATALOG_DIR}\\99_temp\\sector_factors.dbf \n" + "EXP6 1 0Matrix File 1 {SCENARIO_DIR}\\Y{year}_{FareScen}_RFARES.mat \n" + "EXP7 4 0Print Data 1 {SCENARIO_DIR}\\Y{YEAR}_initial_network_costs_summary.dat \n" + "11\n" + "0\n" + "0\n" + "Network_Builder\n" + "NB\n" + "00\n" + "Network Builder\n" + "Building The Network\n" + "Thu Sep 04 20:35:34 2025\n\n" + "D:\\Projects\\20240510_Manila_STM\\Manila_STM\\Manila00.app\n" + "D:\\PROJECTS\\20240510_MANILA_STM\\MANILA_STM\\10_NETWORK_BUILDER\\NETWOR00.APP\n" + "VOYAGER\n" + "D:\\Projects\\20240510_Manila_STM\\Manila_STM\\DEFAULT.VPR\n\n" + "1\n" + "Network Building\n" + "29,-8,0,0,Calibri,48,700,0,0,5066061\n" + "2\n" + "TODO: - Add Nodes and Centroids and Centroid Connectors (can be dummy initially) - DONE - Add capability of adding Schemes - DONE - Build Test Highway Assignment for unit Matrix - DONE - check unconnected zones - DONE - Build PT Files (Factors, line, NT Legs, etc) - Working Now, but nee\n" + "d to renumber the network... - Perform initial Skims for first assignment - DONE\n" + "2441,-1563,0,0,Calibri,14,400,0,0,255\n" + "&End_TextAnnotation\n\n" + "{ZoneVersion,ComboList-CHARACTER,\"Zone Version for TAZ\",\"BASE\", ,\"BASE\",\"250506\"}\n" + "{Network Schemes,EditBox-CHARACTER,\"Network Schemes\",\"schemes_v0.csv\"}\n"; 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