Regular Expressions 101

Save & Manage Regex

  • Current Version: 3
  • 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

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

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 Python, please visit: https://docs.python.org/3/library/re.html