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 = '/(?<record_code>11)(?<bank_code>[0-9]{4})(?<branch_code>[0-9]{4})(?<account_number>[0-9]{10})(?<start_date>[0-9]{6})(?<end_date>[0-9]{6})(?<initial_balance_code>[1-2]{1})(?<initial_balance_amount>[0-9]{14})(?<currency_code>[0-9]{3})(?<information_mode_code>[1-3]{1})(?<abbreviated_name>[a-z A-Z0-9]{26})(?<client_code>[0-9 ]{3})/m'; $str = '111234222212345678900102180202182000000002000009783MI EMPRESA SL 099 2212342222010218010218011112000000000100500000000000ORDEN PAGO RECIB 2212342222010218010218011112000000000050250000000000ORDEN PAGO RECIB 2301LIQ. OP. N 000000000000069 2302AUTOMOCION LAGUNA SL 41001 SEVILLA ES 3312342222123456789000000000000000000000000200000000015075200000000215075978 88999999999999999999000006 110182241902008000281701311701311000019193174009783CARLOS BANANERO RUIZ 2201822419170131170130028972000000000551180000000000ABONO COMP. TRU 30/1/2017 2201822419170131170130021731000000000003500000000000LIQUID.ABONO COM 2301012419-003002935-1 2201822419170131170130041222000000000003502419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 2201822419170131170130041221000000000551182419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 2201822419170131170131028972000000000900600000000000ABONO COMP. TRU 31/1/2017 2201822419170131170131028972000000004984460000000000ABONO COMP. TRU 31/1/2017 2201822419170131170131041221000000000900602419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 2201822419170131170131041221000000004984462419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 2201822419170131170201028972000000001041250000000000ABONO COMP. TRU 30/1/2017 2201822419170131170201028972000000001191960000000000ABONO COMP. TRU 30/1/2017 2201822419170131170201021731000000000007000000000000LIQUID.ABONO COM 2301012419-003002933-8 2201822419170131170201021731000000000016500000000000LIQUID.ABONO COM 2301012419-003002934-0 2201822419170131170201041222000000000007002419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 2201822419170131170201041222000000000016502419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 2201822419170131170201041221000000001191962419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 2201822419170131170201041221000000001041252419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 2201822419170131170202028972000000007865630000000000ABONO COMP. TRU 31/1/2017 2201822419170131170202028972000000008973270000000000ABONO COMP. TRU 31/1/2017 2201822419170131170202041221000000007865632419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 2201822419170131170202041221000000008973272419080002TRASPASO MOVTOS. 2301TRASP. DST: 1128-020-0156824 3301822419020080002800010000000025535350001000000002553535100001919317400978 88999999999999999999000035 '; 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