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 = '/\s{1,}\S{1,}$/m'; $str = 'ITGIS.COMP_OP_STN cos ITGIS.NS_DIVISIONS nsd ITGIS.COMP_OP_STN cos ITGIS.NSPD_RESP_ZONE nrz ITGIS.COMP_OP_STN cos PUBDATA.US_COUNTIES usc ITGIS.COMP_OP_STN cos PUBDATA.US_CITIES_BOUNDARIES uscb ITGIS.COMP_OP_STN cos nsdMatches nsd nrzMatches nrz cityBoundaryMatches countyMatches ITGIS.NSPD_LOCATIONS nl ITGIS.NS_DIVISIONS nd NFSAPP.CONTROL nfsac PUBDATA.US_CITIES c ENGXING.CI_LOCATIONANDCLASSIFICATION cils ITGIS.NS_DIVISIONS nsd ENGXING.CI_LOCATIONANDCLASSIFICATION cils ITGIS.NSPD_RESP_ZONE nrz ENGXING.CI_LOCATIONANDCLASSIFICATION cils PUBDATA.US_COUNTIES usc ENGXING.CI_LOCATIONANDCLASSIFICATION cils PUBDATA.US_CITIES_BOUNDARIES uscb ENGXING.DOTLIST dl INNER JOIN ENGXING.CI_LOCATIONANDCLASSIFICATION cils ENGXING.INVENTORY_QUE q nsdMatches nsd ENGXING.CI_OPERATINGRAILROAD cior nrzMatches nrz cityBoundaryMatches countyMatches ITGIS.NSPD_LOCATIONS nl ITGIS.NS_DIVISIONS nd ENG.ENG_CROSSING ec NFSAPP.CONTROL nfsac PUBDATA.US_CITIES c EGIS.ENG_MPMARK mp ITGIS.NS_DIVISIONS nsd EGIS.ENG_MPMARK mp ITGIS.NSPD_RESP_ZONE nrz EGIS.ENG_MPMARK mp PUBDATA.US_COUNTIES usc EGIS.ENG_MPMARK mp PUBDATA.US_CITIES_BOUNDARIES uscb EGIS.ENG_MPMARK mp nrzMatches nrz nsdMatches nsd cityBoundaryMatches countyMatches ITGIS.NSPD_LOCATIONS nl ITGIS.NS_DIVISIONS nd NFSAPP.CONTROL nfsac PUBDATA.US_CITIES c EGIS.ENG_SWITCH s ITGIS.NS_DIVISIONS nsd EGIS.ENG_SWITCH s ITGIS.NSPD_RESP_ZONE nrz EGIS.ENG_SWITCH s PUBDATA.US_COUNTIES usc EGIS.ENG_SWITCH s PUBDATA.US_CITIES_BOUNDARIES uscb EGIS.ENG_SWITCH s nsdMatches nsd nrzMatches nrz cityBoundaryMatches countyMatches ITGIS.NSPD_LOCATIONS nl ITGIS.NS_DIVISIONS nd NFSAPP.CONTROL nfsac PUBDATA.US_CITIES c EGIS.ENG_TOWER t ITGIS.NS_DIVISIONS nsd EGIS.ENG_TOWER t ITGIS.NSPD_RESP_ZONE nrz EGIS.ENG_TOWER t PUBDATA.US_COUNTIES usc EGIS.ENG_TOWER t PUBDATA.US_CITIES_BOUNDARIES uscb EGIS.ENG_TOWER t nsdMatches nsd nrzMatches nrz cityBoundaryMatches countyMatches ITGIS.NSPD_LOCATIONS nl ITGIS.NS_DIVISIONS nd PUBDATA.US_CITIES c ITGIS.COMP_AEI_SCNR s ITGIS.NS_DIVISIONS nsd ITGIS.COMP_AEI_SCNR s ITGIS.NSPD_RESP_ZONE nrz ITGIS.COMP_AEI_SCNR s PUBDATA.US_COUNTIES usc ITGIS.COMP_AEI_SCNR s PUBDATA.US_CITIES_BOUNDARIES uscb ITGIS.COMP_AEI_SCNR s nsdMatches nsd nrzMatches nrz cityBoundaryMatches countyMatches ITGIS.NSPD_LOCATIONS nl ITGIS.NS_DIVISIONS nd NFSAPP.CONTROL nfsac PUBDATA.US_CITIES c ITGIS.NSPD_LOCATIONS l ITGIS.NS_DIVISIONS nsd ITGIS.NSPD_LOCATIONS l ITGIS.NSPD_RESP_ZONE nrz ITGIS.NSPD_LOCATIONS l PUBDATA.US_COUNTIES usc ITGIS.NSPD_LOCATIONS l PUBDATA.US_CITIES_BOUNDARIES uscb ITGIS.NSPD_LOCATIONS l nsdMatches nsd nrzMatches nrz cityBoundaryMatches countyMatches ITGIS.NSPD_LOCATIONS nl PUBDATA.US_CITIES c NSPD.NSPD_POI poi ITGIS.NS_DIVISIONS nsd NSPD.NSPD_POI poi ITGIS.NSPD_RESP_ZONE nrz NSPD.NSPD_POI poi PUBDATA.US_COUNTIES usc NSPD.NSPD_POI poi PUBDATA.US_CITIES_BOUNDARIES uscb NSPD.NSPD_POI poi nsdMatches nsd nrzMatches nrz cityBoundaryMatches countyMatches ITGIS.NSPD_LOCATIONS nl PUBDATA.US_CITIES c ITGIS.ITGIS_MP100S mp ITGIS.NS_DIVISIONS nsd ITGIS.ITGIS_MP100S mp ITGIS.NSPD_RESP_ZONE nrz ITGIS.ITGIS_MP100S mp PUBDATA.US_COUNTIES usc ITGIS.ITGIS_MP100S mp PUBDATA.US_CITIES_BOUNDARIES uscb ITGIS.ITGIS_MP100S mp NFSAPP.CONTROL nfsac nrzMatches nrz nsdMatches nsd cityBoundaryMatches countyMatches ITGIS.NSPD_LOCATIONS nl ITGIS.NS_DIVISIONS nd PUBDATA.US_CITIES c '; 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