Regular Expressions 101

Save & Manage Regex

  • Current Version: 5
  • 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

$re = '/sample=(?<sample1>\"[^\"]+)\"/'; $str = '2017-12-06T11:57:03.744000 POSITION 0 lang=Albanian sample="Unë mund të ha qelq dhe nuk më gjen gjë." constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T11:40:03.744000 POSITION 1 lang=Arabic sample="أنا قادر على أكل الزجاج و هذا لا يؤلمني." odd=1 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T11:23:03.744000 POSITION 2 lang=Armenian sample="Կրնամ ապակի ուտել և ինծի անհանգիստ չըներ։" constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T11:06:03.744000 POSITION 3 lang=Chinese sample=" 我能吞下玻璃而不傷身體" odd=3 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T10:49:03.744000 POSITION 4 lang=Danish sample="Jeg kan spise glas, det gør ikke ondt på mig." constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T10:32:03.744000 POSITION 5 lang=Euro sample="€." odd=5 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T10:15:03.744000 POSITION 6 lang=French sample="Je peux manger du verre, ça ne me fait pas de mal." constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T09:58:03.744000 POSITION 7 lang=Georgian sample="მინას ვჭამ და არა მტკივა." odd=7 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T09:41:03.744000 POSITION 8 lang=Greek sample="Μπορώ να φάω σπασμένα γυαλιά χωρίς να πάθω τίποτα." constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T09:24:03.744000 POSITION 9 lang=Hawaiian sample="Hiki iaʻu ke ʻai i ke aniani; ʻaʻole nō lā au e ʻeha." odd=9 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T09:07:03.744000 POSITION 10 lang=Hebrew sample="אני יכול לאכול זכוכית וזה לא מזיק לי." constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T08:50:03.744000 POSITION 11 lang=Hindi sample="मैं काँच खा सकता हूँ और मुझे उससे कोई चोट नहीं पहुंचती." odd=11 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T08:33:03.744000 POSITION 12 lang=Hindi sample="मैं काँच खा सकता हूँ, मुझे उस से कोई पीडा नहीं होती." constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T08:16:03.744000 POSITION 13 lang=Icelandic sample="Ég get etið gler án þess að meiða mig." odd=13 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T07:59:03.744000 POSITION 14 lang=Japanese sample="私はガラスを食べられます。それは私を傷つけません" constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T07:42:03.744000 POSITION 15 lang=Korean sample="나는 유리를 먹을 수 있어요. 그래도 아프지 않아요" odd=15 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T07:25:03.744000 POSITION 16 lang=Macedonian sample="Можам да јадам стакло, а не ме штета." constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T07:08:03.744000 POSITION 17 lang=Mongolian sample="Би шил идэй чадна, надад хортой биш" odd=17 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T06:51:03.744000 POSITION 18 lang=Old Norse sample="Ek get etið gler án þess að verða sár." constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script> 2017-12-06T06:34:03.744000 POSITION 19 lang=Polish sample="Mogę jeść szkło, i mi nie szkodzi." odd=19 constant="double quotes" \'single quotes\' \\slashes\\ `~!@#$%^&*()-_=+{}|;:<>,./? [brackets] <script>alert("raw event unescaped!")</script>'; 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