Regular Expressions 101

Save & Share

  • Regex Version: ver. 3
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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*(,\s*){\s*"header"/m'; $str = '[ { "header" : { "channel" : null, "uuid" : "66c3b887-db0f-4e12-8ead-a", "version" : null, "timestamp" : null, "SeqId" : 0, "StatusCode" : 200, "StatusDesc" : "success" }, "MasterData" : { "loc" : { "locBasics" : { "locId" : 2, "locType" : "ORANGE LAB", "locDesc" : "a", "locSubType" : "", "locStatus" : "ACTIVE", "locStartDate" : "2015-03-08", "costCenter" : "123", "dnd" : null, "fiid" : "001", "labCenterNumber" : "123", "locPhone" : null, "gredlID" : "MB22", "retailerStoreNumber" : null }, "locationAddress" : { "latitude" : "11.1", "longitude" : "12.8", "timeZone" : "CENTRAL", "dst" : "DAYLIGHT SAVINGS", "addressLine1" : "ADDRESS ONE", "addressLine2" : "ADDRESS THREE", "recAddress" : "some address", "city" : "CITY", "recCity" : "test city", "state" : "KS", "zip" : "00000", "recZip" : "45235", "country" : "US", "county" : "a COUNTY" }, "market" : { "retailMarket" : "a CENTRAL", "region" : "a", "geoMarket" : "a CENTRAL", "district" : "a SOUTH" } }, "site" : { "siteBasics" : { "siteId" : 2, "siteAccessType" : "RESEARCH", "siteStatus" : "ACTIVE", "siteDescription" : "TEST-24", "onPremise" : "YES", "remoteSite" : "NO", "publicAccess" : "YES", "vendor24HourAccess" : "NO", "customer24HourAccess" : "YES", "mobile" : null, "FeeAmount" : "3" }, "siteHours" : { "serviceHoursBegin" : "08:00,08:00,08:00,08:00,08:00,08:00,08:00,08:00", "serviceHoursEnd" : "17:00,17:00,17:00,17:00,17:00,17:00,17:00,17:00", "dispatchHoursBegin" : "08:00,08:00,08:00,08:00,08:00,08:00,08:00,08:00", "dispatchHoursEnd" : "17:00,17:00,17:00,17:00,17:00,17:00,17:00,17:00", "labHoursBegin" : "08:00,17:00,08:00,08:00,08:00,08:00,08:00,08:00", "labHoursEnd" : "06:00,08:00,17:00,17:00,17:00,17:00,17:00,07:00", "customerHoursBegin" : "08:00,08:00,08:00,08:00,08:00,08:00,08:00,08:00", "customerHoursEnd" : "17:00,17:00,17:00,17:00,17:00,17:00,06:00,17:00", "availableHoursBegin" : "08:00,08:00,08:00,08:00,08:00,08:00,08:00,08:00", "availableHoursEnd" : "17:00,17:00,17:00,17:00,17:00,17:00,05:00,17:00", "mannedHoursBegin" : "08:00,09:09,08:00,08:00,01:00,08:00,08:00,00:00", "mannedHoursEnd" : "17:00,23:00,23:00,23:00,23:00,23:00,23:00,00:00", "holidays" : "0528,0001,2359;0704,0001,2359;0903,0001,2359;1112,0001,2359;1122,0001,2359;1225,0001,2359", "dropboxCutOffTime" : "23:59", "dropboxWindowBegin" : null, "dropboxWindowEnd" : null } }, "asset" : { "labBasics" : { "assetId" : 3, "terminalId" : "a", "terminalType" : "LabTest", "dropboxFriendly" : "TRUE", "dropboxMediaPcssingMode" : "Separate", "machineType" : "d", "assetType" : "a", "originalTerminalId" : "d", "assetUserField1" : null, "mannedProfileKey" : 0, "unMannedProfileKey" : 0, "sampleStatus" : "ACTIVE", "mobile" : "YES", "owner" : "d", "serialNumber" : "6", "sampleAllowed" : "NO", "dSOMarketFlag" : "NO", "manufacturer" : "e", "model" : "3", "family" : "4", "environment" : null, "nickName" : "a", "processingCenter" : "E", "installationDate" : "2015-04-20", "activeDate" : "2015-04-20", "workstationProfile" : "a", "sampleFunction" : "FULL FUNCTION - ENABLED", "hostPlatform" : "a", "initialLoadDate" : "2015-04-20", "sampleRemovalActualDate" : null, "sampleRemovalActualDate" : null, "createDate" : "2018-04-20", "mobileAccessCodeEnabled" : "NO", "voice" : "CAPABLE - ENABLED", "languages" : "CHINESE, ENGLISH, FRENCH, GERMAN", "vendorSiteNumber" : "2", "configRecommendation" : "TEST", "sampleGroup" : "3", "nfcStatus" : "CAPABLE - ENABLED", "nfcModel" : "a", "nfcTypes" : [ "MOBILE", "CARD", "FOB" ] }, "hardware" : { "cardReaderOrientation" : "VERTICAL", "cardReaderType" : "SAMPLE", "sampleRecyclerMode" : "CAPABLE - DISABLED", "sampleDispenserPresent" : "CAPABLE - DISABLED", "monitor" : "TOUCH SCREEN", "operatorPanelPresent" : "CAPABLE - ENABLED", "KeyboardSN" : "3", "Profile" : "DEV_PROFILE", "receiptSize" : null, "screenOrientation" : null, "screenResolution" : "1050X1680", "screenSize" : "15\\"", "noteAcceptorType" : "DBD2", "dropboxSoundVolume" : 58 }, "assetCassettes" : { "cartridgeType1" : "DISPENSE", "cartridgeType2" : "DISPENSE", "cartridgeType3" : "DISPENSE", "cartridgeType4" : "DISPENSE", "sample1" : null, "sample2" : null, "sample3" : "1", "sample4" : "1", "numOfCartridges" : "4", "cassetteConfig" : "test1,test2,test3,test4", "sampleConfig" : "test1,test2,test3,test4", "containers" : null }, "communication" : { "communicationType" : "INTERNAL NETWORK", "macAddress" : "d", "hostName" : "a", "Domain" : null, "networkOwner" : null, "ipDetails" : { "ipAddress" : "104", "ipHost1" : null, "ipHost2" : null, "subnetMask" : "255.255.255.0", "gateway" : "104", "networkAddress" : "13" } }, "contactAssociations" : { "slmAHServiceProvider" : "SADASD", "slmDHServiceProvider" : "TEST123", "slmServiceProvider" : "TEST", "dropboxProvider" : "REPLENISHER COMPANY NAME" } } } }, { "header" : { "channel" : null, "uuid" : "44c3b887-db1f-4e13-8ead-a", "version" : null, "timestamp" : null, "SeqId" : 0, "StatusCode" : 200, "StatusDesc" : "success" }, "MasterData" : { "loc" : { "locBasics" : { "locId" : 2, "locType" : "GREEN LAB", "locDesc" : "a", "locSubType" : "", "locStatus" : "ACTIVE", "locStartDate" : "2015-03-08", "costCenter" : "123", "dnd" : null, "fiid" : "001", "labCenterNumber" : "123", "locPhone" : null, "gredlID" : "MB22", "retailerStoreNumber" : null }, "locationAddress" : { "latitude" : "11.1", "longitude" : "12.8", "timeZone" : "CENTRAL", "dst" : "DAYLIGHT SAVINGS", "addressLine1" : "ADDRESS ONE", "addressLine2" : "ADDRESS THREE", "recAddress" : "some address", "city" : "CITY", "recCity" : "test city", "state" : "KS", "zip" : "00000", "recZip" : "45235", "country" : "US", "county" : "a COUNTY" }, "market" : { "retailMarket" : "a CENTRAL", "region" : "a", "geoMarket" : "a CENTRAL", "district" : "a SOUTH" } }, "site" : { "siteBasics" : { "siteId" : 2, "siteAccessType" : "RESEARCH", "siteStatus" : "ACTIVE", "siteDescription" : "TEST-24", "onPremise" : "YES", "remoteSite" : "NO", "publicAccess" : "YES", "vendor24HourAccess" : "NO", "customer24HourAccess" : "YES", "mobile" : null, "FeeAmount" : "3" }, "siteHours" : { "serviceHoursBegin" : "08:00,08:00,08:00,08:00,08:00,08:00,08:00,08:00", "serviceHoursEnd" : "17:00,17:00,17:00,17:00,17:00,17:00,17:00,17:00", "dispatchHoursBegin" : "08:00,08:00,08:00,08:00,08:00,08:00,08:00,08:00", "dispatchHoursEnd" : "17:00,17:00,17:00,17:00,17:00,17:00,17:00,17:00", "labHoursBegin" : "08:00,17:00,08:00,08:00,08:00,08:00,08:00,08:00", "labHoursEnd" : "06:00,08:00,17:00,17:00,17:00,17:00,17:00,07:00", "customerHoursBegin" : "08:00,08:00,08:00,08:00,08:00,08:00,08:00,08:00", "customerHoursEnd" : "17:00,17:00,17:00,17:00,17:00,17:00,06:00,17:00", "availableHoursBegin" : "08:00,08:00,08:00,08:00,08:00,08:00,08:00,08:00", "availableHoursEnd" : "17:00,17:00,17:00,17:00,17:00,17:00,05:00,17:00", "mannedHoursBegin" : "08:00,09:09,08:00,08:00,01:00,08:00,08:00,00:00", "mannedHoursEnd" : "17:00,23:00,23:00,23:00,23:00,23:00,23:00,00:00", "holidays" : "0528,0001,2359;0704,0001,2359;0903,0001,2359;1112,0001,2359;1122,0001,2359;1225,0001,2359", "dropboxCutOffTime" : "23:59", "dropboxWindowBegin" : null, "dropboxWindowEnd" : null } }, "asset" : { "labBasics" : { "assetId" : 3, "terminalId" : "a", "terminalType" : "LabTest", "dropboxFriendly" : "TRUE", "dropboxMediaPcssingMode" : "Separate", "machineType" : "d", "assetType" : "a", "originalTerminalId" : "d", "assetUserField1" : null, "mannedProfileKey" : 0, "unMannedProfileKey" : 0, "sampleStatus" : "ACTIVE", "mobile" : "YES", "owner" : "d", "serialNumber" : "6", "sampleAllowed" : "NO", "dSOMarketFlag" : "NO", "manufacturer" : "e", "model" : "3", "family" : "4", "environment" : null, "nickName" : "a", "processingCenter" : "E", "installationDate" : "2015-04-20", "activeDate" : "2015-04-20", "workstationProfile" : "a", "sampleFunction" : "FULL FUNCTION - ENABLED", "hostPlatform" : "a", "initialLoadDate" : "2015-04-20", "sampleRemovalActualDate" : null, "sampleRemovalActualDate" : null, "createDate" : "2018-04-20", "mobileAccessCodeEnabled" : "NO", "voice" : "CAPABLE - ENABLED", "languages" : "CHINESE, ENGLISH, FRENCH, GERMAN", "vendorSiteNumber" : "2", "configRecommendation" : "TEST", "sampleGroup" : "3", "nfcStatus" : "CAPABLE - ENABLED", "nfcModel" : "a", "nfcTypes" : [ "MOBILE", "CARD", "FOB" ] }, "hardware" : { "cardReaderOrientation" : "VERTICAL", "cardReaderType" : "SAMPLE", "sampleRecyclerMode" : "CAPABLE - DISABLED", "sampleDispenserPresent" : "CAPABLE - DISABLED", "monitor" : "TOUCH SCREEN", "operatorPanelPresent" : "CAPABLE - ENABLED", "KeyboardSN" : "3", "Profile" : "DEV_PROFILE", "receiptSize" : null, "screenOrientation" : null, "screenResolution" : "1050X1680", "screenSize" : "15\\"", "noteAcceptorType" : "DBD2", "dropboxSoundVolume" : 58 }, "assetCassettes" : { "cartridgeType1" : "DISPENSE", "cartridgeType2" : "DISPENSE", "cartridgeType3" : "DISPENSE", "cartridgeType4" : "DISPENSE", "sample1" : null, "sample2" : null, "sample3" : "1", "sample4" : "1", "numOfCartridges" : "4", "cassetteConfig" : "test1,test2,test3,test4", "sampleConfig" : "test1,test2,test3,test4", "containers" : null }, "communication" : { "communicationType" : "INTERNAL NETWORK", "macAddress" : "d", "hostName" : "a", "Domain" : null, "networkOwner" : null, "ipDetails" : { "ipAddress" : "104", "ipHost1" : null, "ipHost2" : null, "subnetMask" : "255.255.255.0", "gateway" : "104", "networkAddress" : "13" } }, "contactAssociations" : { "slmAHServiceProvider" : "SADASD", "slmDHServiceProvider" : "TEST123", "slmServiceProvider" : "TEST", "dropboxProvider" : "REPLENISHER COMPANY NAME" } } } } ]'; 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