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 = '/"(.+?)".+?/m'; $str = '{ "timelineObjects" : [ { "activitySegment" : { "startLocation" : { "latitudeE7" : 84876125, "longitudeE7" : 986251728 }, "endLocation" : { "latitudeE7" : 81501293, "longitudeE7" : 988554012 }, "duration" : { "startTimestampMs" : "1577853940096", "endTimestampMs" : "1577867160036" }, "distance" : 45275, "activityType" : "IN_PASSENGER_VEHICLE", "confidence" : "HIGH", "activities" : [ { "activityType" : "IN_PASSENGER_VEHICLE", "probability" : 78.98348569869995 }, { "activityType" : "STILL", "probability" : 13.971047103404999 }, { "activityType" : "MOTORCYCLING", "probability" : 3.0464861541986465 }, { "activityType" : "WALKING", "probability" : 2.5266656652092934 }, { "activityType" : "IN_FERRY", "probability" : 0.7077858783304691 }, { "activityType" : "CYCLING", "probability" : 0.23177380207926035 }, { "activityType" : "FLYING", "probability" : 0.2262754598632455 }, { "activityType" : "IN_BUS", "probability" : 0.1849415129981935 }, { "activityType" : "RUNNING", "probability" : 0.0680008321069181 }, { "activityType" : "SAILING", "probability" : 0.029427077970467508 }, { "activityType" : "SKIING", "probability" : 0.015666104445699602 }, { "activityType" : "IN_TRAIN", "probability" : 0.006996936281211674 }, { "activityType" : "IN_SUBWAY", "probability" : 0.0010493132322153542 }, { "activityType" : "IN_TRAM", "probability" : 3.152051021970692E-4 }, { "activityType" : "IN_VEHICLE", "probability" : 8.468594501209736E-5 } ], "simplifiedRawPath" : { "points" : [ { "latE7" : 81042775, "lngE7" : 989657755, "timestampMs" : "1577867101472", "accuracyMeters" : 122 } ] } } }, { "placeVisit" : { "location" : { "latitudeE7" : 81037885, "longitudeE7" : 989663263, "placeId" : "ChIJrX3SBcuTUTAR4r4hEgpoSvA", "address" : "313 หมู่ 12 อำเภอ เมือง\\nตำบล กระบี่น้อย อำเภอเมืองกระบี่\\nกระบี่ 81000\\nThailand", "name" : "สำนักงานทางหลวงที่ 17", "sourceInfo" : { "deviceTag" : -1189270403 }, "locationConfidence" : 63.438793 }, "duration" : { "startTimestampMs" : "1577867160036", "endTimestampMs" : "1577873822494" }, "placeConfidence" : "MEDIUM_CONFIDENCE", "centerLatE7" : 81042540, "centerLngE7" : 989657723, "visitConfidence" : 91, "otherCandidateLocations" : [ { "latitudeE7" : 81035660, "longitudeE7" : 989642884, "placeId" : "ChIJmfJgxcuTUTAR-VQR_9hOeGk", "locationConfidence" : 21.532362 } } } ] }'; 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