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 = '/<xfi_cd.*?>(?\'xfi_cd\'.*?)<\x2Fxfi_cd>.*?<ins_libl.*?>(?\'ins_libl\'.*?)<\x2Fins_libl>.*?<apt_type.*?>(?\'apt_type\'.*?)<\x2Fapt_type>.*?<apt_nom.*?>(?\'apt_nom\'.*?)<\x2Fapt_nom>.*?<apt_telephone.*?>(?\'apt_telephone\'.*?)<\x2Fapt_telephone>.*?<tsy_lib.*?>(?\'tsy_lib\'.*?)<\x2Ftsy_lib>.*?<qsy_lib.*?>(?\'qsy_lib\'.*?)<\x2Fqsy_lib>.*?<num_externe.*?>(?\'num_externe\'.*?)<\x2Fnum_externe>.*?<urg_cd.*?>(?\'urg_cd\'.*?)<\x2Furg_cd>.*?<commentaire_externe.*?>(?\'commentaire_externe\'.*?)<\x2Fcommentaire_externe>/m'; $str = '<urn:nouvelle_intervention201408 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <param0 xsi:type="enc:fr_elyo_elyodirect_webservices_Intervention201408" xmlns:enc="urn:fr-elyo-elyodirect-webservices-IP2C/encodedTypes"> <xfi_cd xsi:type="xsd:string">K</xfi_cd> <ins_libl xsi:type="xsd:string">29540002</ins_libl> <apt_type xsi:type="xsd:string">Centre appels</apt_type> <apt_nom xsi:type="xsd:string">9800 CECO</apt_nom> <apt_telephone xsi:type="xsd:string">902030255 (33284)</apt_telephone> <tsy_lib xsi:type="xsd:string">Carpinteria Interior Oficina</tsy_lib> <qsy_lib xsi:type="xsd:string">Maneta/pomo </qsy_lib> <num_externe xsi:type="xsd:string">IM12035415</num_externe> <urg_cd xsi:type="xsd:string">1</urg_cd> <commentaire_externe xsi:type="xsd:string">Pomo puerta de acceso cae</commentaire_externe> </param0> </urn:nouvelle_intervention201408> ________________________________ Advertencia legal: Este mensaje y, en su caso, los ficheros anexos son confidenciales, especialmente en lo que respecta a los datos personales, y se dirigen exclusivamente al destinatario referenciado. Si usted no lo es y lo ha recibido por error o tiene conocimiento del mismo por cualquier motivo, le rogamos que nos lo comunique por este medio y proceda a destruirlo o borrarlo, y que en todo caso se abstenga de utilizar, reproducir, alterar, archivar o comunicar a terceros el presente mensaje y ficheros anexos, todo ello bajo pena de incurrir en responsabilidades legales. El emisor no garantiza la integridad, rapidez o seguridad del presente correo, ni se responsabiliza de posibles perjuicios derivados de la captura, incorporaciones de virus o cualesquiera otras manipulaciones efectuadas por terceros. ________________________________ Advertiment legal: Aquest missatge i, si escau, els fitxers annexos tenen caire confidencial, especialment pel que fa a les dades personals, i s\'adrecen exclusivament al destinatari referenciat. Si no es tracta d\'aquest i l\'ha rebut per error o se li ha fet arribar per qualsevol motiu, li preguem que ens ho comuniqui per aquesta mateixa via i el destrueixi o l\'esborri, i que en tot cas s\'abstingui d\'utilitzar, reproduir, alterar, arxivar o comunicar a tercers aquest missatge i fitxers annexos, tot sota pena d\'entrar en responsabilitats legals. L\'emissor no garanteix la integritat, la rapidesa o la seguretat d\'aquest correu, ni es responsabilitza de possibles perjudicis derivats de la captura, incorporacions de virus o qualsevol altres manipulacions que facin tercers. ________________________________ Disclaimer: This message and any attached files transmitted with it, is confidential, especially as regards personal data. It is intended solely for the use of the individual or entity to whom it is addressed. If you are not the intended recipient and have received this information in error or have accessed it for any reason, please notify us of this fact by email reply and then destroy or delete the message, refraining from any reproduction, use, alteration, filing or communication to third parties of this message and attached files on penalty of incurring legal responsibilities. The sender does not guarantee the integrity, the accuracy, the swift delivery or the security of this email transmission, and assumes no responsibility for any possible damage incurred through data capture, virus incorporation or any manipulation carried out by third parties. ________________________________'; 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