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

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