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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
g

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @/ ((?:(?# path without "" )(?<opening>(?# 'C:/', '//', '//./<UNC/C:>', '//?/<UNC/C:>' or '%VariableWindows%')(?<UNCPrefix>[\/\\][\/\\][?.][\/\\](?:UNC[\/\\])?)?(?<montage>\b[a-zA-Z]:[\/\\])|(?:(?:(?&UNCPrefix))|(?:[\/\\][\/\\](?!(?&montage))))|(?:%\w+%[\/\\]?))(?:(?# directory btw // )[^\/\\<>:""|?\n\r ][^\/\\<>:""|?\n\r]*(?<![ ])[\/\\])*(?:(?#we search for fileName only if next character is pathFriendly)(?=[^\/\\<>:""'|?\n\r;, ])(?:(?#name file ? dir ?)(?:[^\/\\<>:""|?\n\r;, .](?: (?=[\w\-]))?(?:\*(?!= ))?(?!(?&montage)))+)?(?:(?#extention)\.\w+)*))|(?:(?# path quoted "" or '' )[""'](?&opening)(?=.*?[""'])(?:[^\/\\<>:'""|?\n\r]+[\/\\]?)+?[""'])) /; string input = @"\\LOCALHOST\c$\temp\test-file.txt"" @""c:\temp\test-file.txt"", @""\\127.0.0.1\c$\temp\test-file.txt"", @""\\LOCALHOST\c$\ temp\test-file.txt"", @""\\.\c:\temp\test-file.txt"", @""\\?\c:\temp\est-file.txt"", @""\\.\UNC\LOCALHOST\c$\temp\test-file.txt"", @""\\127.0.0.1\c$\temp\test-file.txt"" --------------------------- Tentative d'accès à C:\Users\tpgz4017\App - Data\Local\Temp\tempShapeFile_CrossWave Calibration Zones - Atoll CrossWave Model.shx après sa fin. --------------------------- file:///C:/Users/Downloads/20220516_32289275_1049383.pdf file://p-eco2.rd.fr/vol_H0037_01$/599/livraison/20220516_32289275_1049383.pdf --> couper les path apres le '\ ', meme que on est arrivé au fichier c:\temp\test-file.txt"", \\127.0.0.1\c$\temp\test-file.txt"", \\LOCALHOST\c$\ temp\test-file.txt"", \\LOCALHOST\c$ \temp\test-file.txt"", \\.\c:\temp\t\est-file.txt"", \\?\c:\temp\test-file.txt"", \\.\UNC\LOCALHOST\c$\temp\test-file.txt"", \\?\UNC\ServerName\ temp\test-file.txt"", \\127.0.0.1\c$\temp\test-file.txt"" \\?\server1\e:\utilities\\filecomparer\ C:/test\gvk.hv/fgfjgjj bdsdfus(fg) C:/test\gvkhv/../fgfjgjjb/yfigfi C:/test\gvk.hv/fgfj.gjjb/uhloext C:/test\gvk.hv/fgfj.gjjb/uhloext.ds C:/test\gvk.hv/fgfj.gjjb/uhloext C:/UNC/test\gvk.hv/fgfj.gjjb/uhloext.ds Site0 / 3: - Warning . See log file 'C:\ProgramData\InfoVista\Planet 7.4\7.4\RPE\Log\Plugins\Universal_Model_masked\log_Universal_Model.txt' for details C:/test\gvk.hv/fgfj.gjjb/uhloext.ds.yi : gf \\b-renice\sauvegardes\B-HIER\GEO\Geo_NetAct_Atoll_Planet\UR_Est\Polygon\Haguenau\Building\Haguenau hgtfhyt ""C:/te-st.html"" ""C:/te-st.html"" gd""dhbcsk ""C:/te/dsst.ikpo fdsf ""C:\test"" ""C:// test.html"" gd ""//te s t/e, llo.html C:/test\f/uhlo/. C://te?st.html b-renice\sauvegardes\B-HIER\GEO\Geo_NetAct_Atoll_Planet\UR_Est\Custom Data"" ; dfsdf ""\\b-renice\sauvegardes\B-HIER\GEO\Geo_NetAct_Atoll_Planet\UR_Est\Custom Data"" ; dfsdf ""\\ Haguenau_Building.tab : Data format of \\b-renice\sauvegardes\B-HIER\GEO\Geo_NetAct_Atoll_Planet\UR_Est\Polygon\Haguenau\Building\Haguenau Building.* C: is invalid Haguenau_Building.tab : Data format of \\b-renice\sauvegardes\B-HIER\GEO\Geo NetAct Atoll_Planet\UR_Est\Polygon\Haguenau\Building\Haguenau Building.TAB, is invalid Haguenau_Building.tab : Data format of \\b-renice\sauvegardes\B-HIER\GEO\Geo_NetAct_Atoll_Planet\UR_Est\Polygon\Haguenau\Building\Haguenau Buildi*.*ng.*, is invalid C:/test/../hjgbkl C:/test/../hjgbkl.gfgdfgrdgfdgr C:/test/../hjgbkl C:/test.html C://test/ .h/hel,lo.html//test/./hello.html C:/test//hello.html //test //hello.html /test ""%tmp%/fsdfs"" %tmp%/fsdfs ERROR 8/31/2021 - 6:45:39 PM HighResClutter .RasterFile : \\b-ren ice\sauv egardes\B-HIER\GEO%dsq%\NewJersey_NewYork\DTM\DTM\CENTRAL_JERSE..Y_New_York_2 m_Z18N_0_DTM_02_06.bil : Le fichier spécifié est introuvable. \\b-ren ice\sauv egardes\..\B-HIER\GEO\NewJersey_NewYork\DTM\DTM\CENTRAL_JERSE..Y_New_York_2 m_Z18N_0_DTM_02_06.bil C:\b-ren ice\sauv egardes\B-HIER\GEO\NewJersey_NewYork\DTM\DTM\CENTRAL_JERSE..Y_New_York_2 m_Z18N_0_DTM_02_06.bil \\b-ren ice\sauv egardes\B-HIER\GEO\NewJersey_NewYork\DTM\DTM\CENTRAL_JER SE.Y_New_York_2 m_Z18N_0_DTM_02_06.bil. //test.html \\10.1.1.107 //10.1.1.107/test.html //10.1.1.107/te st/hello.html //10.1.1.107/test/hello //test/hello.txt //test/hello.txt. /test/html /tes?t/html /test.html test.html // / \\\rged\bfg \\ /t!esrtr C:/hel**o \\.\UNC\Server\Share\Test\Foo.txt \\?\UNC\Server\Share\Test\Foo.txt Pour les chemins UNC de périphérique, la partie serveur/partage forme le volume. Par exemple, dans \\?\server1\e:\utilities\\filecomparer\ , la partie serveur/partage est server1\utilities . Ceci est important quand "; foreach (Match m in Regex.Matches(input, pattern)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx