Regular Expressions 101

Save & Share

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 = "^((\\.{2}\\\\)+|(\\.?\\\\)?).+"; final String string = "..\\meeting_minutes.txt\n" + "..\\..\\profile.txt\n" + "Reports\\2023\\summary.txt\n" + "\\Reports\\2023\\summary.txt\n" + ".\\Reports\\2023\\summary.txt\n" + "..\\Projects\\project_a.docx\n" + "..\\Projects\\project a.docx\n" + ".\\my_file.txt\n" + ".\\my file.txt\n" + "..\\..\\data\n" + "..\\Music#a\\file.mp3\n" + "..\\Music[Genre]\\file.mp3\n" + "..\\Music(Genre)\\file.mp3\n" + "..\\Music-Hardcore-Metal\\file.mp3\n" + "..\\Documents\\My+File.xlsx\n" + "..\\Documents\\Some{Document}.py\n" + "..\\Files\\Afilewithweird;Characters'`.doc\n" + "..\\Music#^@!()-+{};',.`~a\\file.mp3\n" + "..\\..\n" + "..\\..\\Final\n" + ".\n" + ".\\..\\Soils\n" + "..\\..\\.\\Final\\..\\Shapefiles\\.\\Landuse\n" + "./data-files/geological/EQs_last_week_of_2021.csv../data-files/geological/\n" + "EQs_last_week_of_2021.csv../../data-files/EQs_last_week_of_2021.csv../../../data-files/\n" + "EQs_last_week_of_2021.csv../../../data-files/geological/EQs_last_week_of_2021.csv\n" + "../pictures/file.jpg\n" + ".\\temp\\[backup]_2024\\final-version (2).bak\n" + "assets\\images\\new.logo-2025_v2\\icon@2x#1.png\n" + "..\\users\\Jay Soren\\Documents (Archived)\\plan[final].docx\n" + "projects\\#active-clients\\ACME_Corp\\Q2 Report\\summary v1.3.pdf\n" + "config\\env-settings\\!urgent.env\n" + "media\\🎵 music\\lo-fi & chill\\set_03 (remastered).wav\n" + "..\\..\\data\\[raw]_input_🧪\\test-sample(01).csv\n" + "src\\core.modules\\engine@v4.2.1.dll\n" + "docs\\2025_06\\meeting_notes (draft)\\📝summary_notes.md\n" + "themes\\🌑 darkmode (beta)\\style-final!.css\n" + "..\\..\\logs\\🪵 log-archive\\2023-12-25 [Christmas].log\n" + "downloads\\zips\\patch_update v3.4-final!.zip\n" + "build\\#output$\\v2.1.1\\installer(64bit).exe\n" + "components\\UI-Toolkit_🔥\\modal.dialog.js\n" + "scripts\\batch jobs\\cleanup-temp_files!.bat\n" + "resources\\📁 static\\fonts\\Roboto_Bold-Italic.ttf\n" + "tests\\[integration]_suite#2\\test-case(01).spec.js\n" + "temp\\$$merge_conflict\\attempt_#3\\resolved✅.txt\n" + "locales\\en-US\\messages(v1.0.0).json\n" + "backup\\[legacy]_configs\\1999.version.ini\n" + "src\\modules\\@internal\\storage-handler.ts\n" + "..\\releases\\build#2025.06.14\\installer-vFinal.exe\n" + "app\\#dev[tools]\\init.env.local\n" + "templates\\html\\base.template[mobile] v2.3.html\n" + "tools\\@scripts\\🧰_toolbelt\\init+config.ps1\n" + "test_data\\unit_tests\\input(1)_#valid.json\n" + "uploads\\archive\\⚠️_caution\\delete_me_later!.txt\n" + "plugins\\[effects]_pack_v2.0\\shine++.aex\n" + "scripts\\build-process\\generate_docs.sh\n" + "media\\[video]_exports\\final-cut[HD] 2025-06.mp4\n" + "src\\experimental\\feat_XYZ\\🤖 robot_model_v7.py\n" + "themes\\🖼️_gallery-view\\art_styles(alt).css\n" + "..\\..\\app\\modules@deprecated\\beta_handler_old.py\n" + "lib\\_core_\\v5.5.0-preview\\main-module.dll\n" + "config\\!config\\alt-🧬variant(2024).cfg\n" + "resources\\svg\\📦 package_icons\\box-outline#new.svg\n" + "env\\.private\\__secrets__\\[do_not_share].key\n" + "db\\migrations\\version_003(rollback).sql\n" + "projects\\🔥_hotfix-2025.06.01\\readme[fixed].md\n" + "user\\@jay-s\\📂work-in-progress\\demo_v0.1(🛠️).pptx\n" + "docs\\[TOC]_index\\ch-02#advanced-topics.md\n" + "downloads\\[temp]_🧼cleanup_dir\\file 001.tmp\n" + "scripts\\dev\\postinstall_hooks\\hook-runner!.ps1\n" + "logs\\📊_analytics\\[monthly]_stats-06-2025.csv\n" + "tests\\[🔥stress]_loadtest-v99-final_(PASS).log\n" + "source\\hidden\\.config_dir\\!local.env\n" + "tasks\\[🧾]_todo_list (critical).txt\n" + "patches\\archive\\ver_1.0.0-beta2#RC1.zip\n" + "themes\\theme_pack-v9.9\\[ocean🌊]\\index.theme\n" + "assets\\icons_special\\svg[✔️].iconset\\✅checked.svg\n" + "utils\\run$now\\📈metrics-collector.ts\n" + "notes\\[📚]_reference_materials (v3).pdf\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