Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Fork Regex
    ctrl+s
  • Add to Community Library

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

/
/
gixu

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/# Definição de ordens (?(DEFINE)(?P<unidades> um|dois|tr[eê]s|quatro|cinco|meia|se(?:is|te)|oito|nove )) (?(DEFINE)(?P<dezenas_dez> d(?:ez(?:e(?:nove|sse(?:is|te))|oito)?|oze)|onze|treze|catorze|quinze )) (?(DEFINE)(?P<dezenas_exceto_dez> vinte|trinta|(?:quar|cinqu|se(?:ss|t)|oit|nov)enta )) (?(DEFINE)(?P<dezenas> (?P>dezenas_dez)|(?P>dezenas_exceto_dez) )) (?(DEFINE)(?P<dezenas_ou_unidades> (?P>dezenas)|(?P>unidades) )) (?(DEFINE)(?P<centenas> ce(?:m|ntos?)|(?:qu(?:atroc|inh)|(?:du|tre|se(?:is|te)|oito|nove)[cz])entos? )) (?(DEFINE)(?P<mil> mil )) (?(DEFINE)(?P<milhoes> (?:(?:[mb]|tr)i|qu(?:atri|inqua))lh(?:[aã]o|[oõ]es) )) (?(DEFINE)(?P<s> [ ]+ )) (?(DEFINE)(?P<e> e(?P>s) )) #Regras \b(?: #1. Entre dezenas>=20 e unidades (?P>dezenas_exceto_dez)(?P>s)(?=(?P>unidades)\b) | #2. Entre centenas e dezenas ou unidades (?P>centenas)(?P>s)(?=(?P>dezenas_ou_unidades)\b) | #3-4. Entre milhares... (?P>mil)(?P>s)(?= (?: #3. ... e dezenas ou unidades (?P>dezenas_ou_unidades) | #4. ... e centenas, somente se não houver dezenas ou unidades (?P>centenas)(?!(?P>s)(?P>e)?(?P>dezenas_ou_unidades)\b) ) \b ) | #5. Entre milhões e dezenas ou unidades (que não sejam unidades ou dezenas de milhões ou unidades ou dezenas de milhares) (?P>milhoes)(?P>s)(?= (?P>dezenas_ou_unidades)(?!(?P>s)(?P>e)?(?:(?P>unidades)(?P>s)(?P>e)?)?(?:(?P>milhoes)|(?P>mil))\b)\b ) ) \b #Reset \K/ixu'; $str = 'vinte cinco vinte cinco mil vinte cinco reais vinte cinco reais e vinte cinco centavos aaa bbb ccc dois mil trezentos dois mil trezentos quarenta cinco dois milhões trinta um dois milhões trinta um mil dois milhões trinta mil cento vinte três milhões quatrocentos cinquenta seis mil setecentos oitenta nove'; $subst = "e "; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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