Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • 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
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 = '/^(?:[^\{]*[\{]){2}\s(?<ReadablePayload>[^\{]*)[\}]\S\s[^\{]*[\{]\s([^\}]*[\}])/s'; $str = '2019-02-08 00:54:43 [TRACE] Malformed message { [TRACE] Readable Payload { UNH+20038142932000+AIRRQT:15:2:1A+cepSwzsAXFw=800\'ORG+1A:MUC+1234567:NCE1A0950+++T\'BLK+152+RF++000+0000000000+1A:1290861+001:001\'AMD++07:00000000::07FEB++1A:1290861+1A:1290861+MUC:1A: +00:01+++AMSSG34AA:57211534:02+++++++++AMSSG34AA:57211534\'AVC+IBERIA+IB:0755\'BIN+TRFP\'CSC+7906:/++9993WSSU\'DAT+180130+190207+190207\'HAS+000+000:X:OPO+XXX+MAD+XXX+XX:XXXXX:X:X: : : : +XXXX++0\'HAS+000+000:X:MAD+XXX+PMI+XXX+XX:XXXXX:X:X: : : : +XXXX++0\'HAS+000+000:X:PMI+XXX+MAD+XXX+XX:XXXXX:X:X: : : : +XXXX++0\'HAS+000+000:X:MAD+XXX+OPO+XXX+XX:XXXXX:X:X: : : : +XXXX++0\'RFD+L+30JAN18++EUR:88.00:88.00:0.00++XT:48.90:48.90\'KFL\'KRF+ +Q:EUR:3.47:PT: *Q:EUR:10.09:YP: *Q:EUR:25.92:JD: *Q:EUR:7.69:QV: *Q:EUR:1.73:OG: \'ING\'INM+001+01:SANTOS/CARLA MS\'TTN+E+075+5169861484\'EQN+1\'CPN+1*2*3*4\'REF+075-5169861484+07FEB19\'END+X\'UNT+23+1\' }, [TRACE] Reason { Mandatory element is missing. [TRACE] Error at <src/CBRSegmentDecoders.cpp:21405 [TRACE] Error in segment CSC 06 1 1A TKA in element #2. [TRACE] ------ [TRACE] Error at <src/CBRMessageDecoders.cpp:121 [TRACE] Error in group Group id: _294728_G_CBR in element #3. [TRACE] ------ [TRACE] Decoding error in message AIRRQT 15 2 1A PNR in element #4 at character 236 of the buffer, using charset B [TRACE] Converted segments: ORG - BLK - AMD - AVC - BIN - [TRACE] Cannot convert CSC from here==>+9993WSSU\'Last segment correctly processed: CSC+7906:/++9993WSSU\' [TRACE] }, [TRACE] Rejection type { T }, [TRACE] Current line { 251590 }, [TRACE] }'; 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