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 = '/(?siU).*\"temp\":(.*),.*\"description\":\"(.*)\".*daily.*\"dt\":(.*),.*\"min\":(.*),.*\"max\":(.*),.*\"description\":\"(.*)\".*\"dt\":(.*),.*\"min\":(.*),.*\"max\":(.*),.*\"description\":\"(.*)\".*\"dt\":(.*),.*\"min\":(.*),.*\"max\":(.*),.*\"description\":\"(.*)\".*\"dt\":(.*),.*\"min\":(.*),.*\"max\":(.*),.*\"description\":\"(.*)\".*\"dt\":(.*),.*\"min\":(.*),.*\"max\":(.*),.*\"description\":\"(.*)\".*\"dt\":(.*),.*\"min\":(.*),.*\"max\":(.*),.*\"description\":\"(.*)\".*\"dt\":(.*),.*\"min\":(.*),.*\"max\":(.*),.*\"description\":\"(.*)\".*\"dt\":(.*),.*\"min\":(.*),.*\"max\":(.*),.*\"description\":\"(.*)\".*/m'; $str = '{"lat":-34.08,"lon":150.79,"timezone":"Australia/Sydney","current":{"dt":1588385816,"sunrise":1588365147,"sunset":1588403702,"temp":17.07,"feels_like":11.01,"pressure":1003,"humidity":46,"dew_point":5.37,"uvi":3.47,"clouds":0,"wind_speed":7.15,"wind_deg":6,"wind_gust":12.52,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}]},"daily":[{"dt":1588381200,"sunrise":1588365147,"sunset":1588403702,"temp":{"day":17.07,"min":8.55,"max":17.07,"night":8.55,"eve":14.09,"morn":17.07},"feels_like":{"day":12.24,"night":4.21,"eve":8.47,"morn":12.24},"pressure":1003,"humidity":46,"dew_point":5.37,"wind_speed":5.39,"wind_deg":279,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":0,"uvi":3.47},{"dt":1588467600,"sunrise":1588451594,"sunset":1588490045,"temp":{"day":14.88,"min":7.68,"max":17.78,"night":8.4,"eve":16.89,"morn":8.56},"feels_like":{"day":10.2,"night":5.52,"eve":14.86,"morn":4.49},"pressure":1018,"humidity":44,"dew_point":3.39,"wind_speed":4.47,"wind_deg":218,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":0,"uvi":3.57},{"dt":1588554000,"sunrise":1588538040,"sunset":1588576388,"temp":{"day":15.31,"min":6.68,"max":17.69,"night":9.37,"eve":15.32,"morn":6.83},"feels_like":{"day":13.61,"night":6.72,"eve":12.09,"morn":4.14},"pressure":1026,"humidity":55,"dew_point":6.95,"wind_speed":1.22,"wind_deg":179,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":1,"uvi":3.58},{"dt":1588640400,"sunrise":1588624487,"sunset":1588662733,"temp":{"day":16.72,"min":9,"max":17.88,"night":11.03,"eve":17.09,"morn":9},"feels_like":{"day":15.02,"night":9.63,"eve":15.93,"morn":6.39},"pressure":1030,"humidity":63,"dew_point":10.15,"wind_speed":2.35,"wind_deg":188,"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":20,"rain":0.46,"uvi":3.68},{"dt":1588726800,"sunrise":1588710934,"sunset":1588749078,"temp":{"day":16.47,"min":9.47,"max":20.25,"night":12.26,"eve":19.16,"morn":9.82},"feels_like":{"day":14.75,"night":11.65,"eve":17.97,"morn":8.33},"pressure":1029,"humidity":62,"dew_point":9.75,"wind_speed":2.2,"wind_deg":344,"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":64,"uvi":3.7},{"dt":1588813200,"sunrise":1588797380,"sunset":1588835425,"temp":{"day":17.89,"min":9.93,"max":21.04,"night":14.29,"eve":20.37,"morn":10.29},"feels_like":{"day":16.46,"night":13.24,"eve":19.37,"morn":9.06},"pressure":1025,"humidity":51,"dew_point":8.18,"wind_speed":1.25,"wind_deg":327,"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":93,"uvi":3.88},{"dt":1588899600,"sunrise":1588883826,"sunset":1588921774,"temp":{"day":18.95,"min":10.71,"max":23.82,"night":14.21,"eve":22.89,"morn":11.2},"feels_like":{"day":17.59,"night":13.29,"eve":21.52,"morn":10.21},"pressure":1022,"humidity":55,"dew_point":10.17,"wind_speed":1.89,"wind_deg":334,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":0,"uvi":3.45},{"dt":1588986000,"sunrise":1588970273,"sunset":1589008123,"temp":{"day":19.74,"min":11.48,"max":25.25,"night":14.53,"eve":23.02,"morn":11.73},"feels_like":{"day":18.36,"night":13.58,"eve":21.48,"morn":10.92},"pressure":1020,"humidity":52,"dew_point":10.27,"wind_speed":1.88,"wind_deg":336,"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":0,"uvi":3.42}]}'; 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