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
No Match

r"
"
gm

Test String

Code Generator

Generated Code

re = /(\{\s*(\"uid\"[\S ]+\s*)(\"commandName\": \"(?!OpenSpreadsheet).*\"[\S ]*\s*)(\"packageName\": \"Excel_MS\"[\S ]*\s*)(\"disabled\"[\S ]*\s*)(\"attributes\": \[(?:[\s\S])*?\])\s*\})/m str = '{(\\"packageName\\": \\".+\\",\\s+)) "triggers": [], "nodes": [ { "uid": "c381755e-45af-4521-a5da-ccb611b714de", "commandName": "try", "packageName": "ErrorHandler", "disabled": false, "children": [ { "uid": "112fb642-d36b-40f0-98dd-ca3ffbdf245c", "commandName": "OpenSpreadsheet", "packageName": "Excel_MS", "disabled": false, "attributes": [ { "name": "session", "value": { "type": "STRING", "string": "Email Config" } }, { "name": "filePath", "value": { "type": "FILE", "expression": "file://$sEmailConfig_Path$/Email_Config.xlsx" } }, { "name": "isSpecificSheet", "value": { "type": "BOOLEAN", "boolean": false } }, { "name": "fileAccessMode", "value": { "type": "STRING", "string": "EDIT" } }, { "name": "isSecure", "value": { "type": "BOOLEAN", "boolean": false } }, { "name": "containsHeader", "value": { "type": "BOOLEAN", "boolean": true } }, { "name": "loadAddIns", "value": { "type": "BOOLEAN", "boolean": false } } ], "returnTo": { "type": "SESSION", "sessionName": { "type": "STRING", "string": "Email Config" }, "sessionTarget": "LOCAL" } }, { "uid": "5dde9342-f376-40a6-b989-4b2e1ca27d49", "commandName": "step", "packageName": "Step", "disabled": false, "children": [ { "uid": "0fc45d7d-1e41-449e-be34-39d58c160196", "commandName": "if", "packageName": "If", "disabled": false, "children": [ { "uid": "ce33cad3-9f43-4ee4-8840-0746097df93a", "commandName": "SwitchToSheet", "packageName": "Excel_MS", "disabled": false, "attributes": [ { "name": "session", "value": { "type": "SESSION", "sessionName": { "type": "STRING", "string": "Email Config" } } }, { "name": "sheetOption", "value": { "type": "STRING", "string": "BYNAME" } }, { "name": "sheetName", "value": { "type": "STRING", "string": "Complete" } } ] } ], "branches": [], "attributes": [ { "name": "condition", "attributes": [ { "name": "variable", "value": { "type": "STRING", "expression": "$sTag$" } }, { "name": "operator", "value": { "type": "STRING", "string": "EQ" } }, { "name": "value", "value": { "type": "STRING", "string": "Complete" } }, { "name": "matchCase", "value": { "type": "BOOLEAN", "boolean": true } }, { "name": "isIgnoreCarriage", "value": { "type": "BOOLEAN", "boolean": false } } ], "value": { "type": "CONDITIONAL", "conditionalName": "stringVariable", "packageName": "String" } } ] }, { "uid": "03a75bd4-d238-4d5f-990b-e5bc78c36350", "commandName": "if", "packageName": "If", "disabled": false, "children": [ { "uid": "992db39c-a0ec-4c5b-bdbe-1eda2082bc5b", "commandName": "SwitchToSheet", "packageName": "Excel_MS", "disabled": false, "attributes": [ { "name": "session", "value": { "type": "SESSION", "sessionName": { "type": "STRING", "string": "Email Config" } } }, { "name": "sheetOption", "value": { "type": "STRING", "string": "BYNAME" } }, { "name": "sheetName", "value": { "type": "STRING", "string": "Error" } } ] } ], "branches": [], "attributes": [ { "name": "condition", "attributes": [ { "name": "variable", "value": { "type": "STRING", "expression": "$sTag$" } }, { "name": "operator", "value": { "type": "STRING", "string": "EQ" } }, { "name": "value", "value": { "type": "STRING", "string": "Error" } }, { "name": "matchCase", "value": { "type": "BOOLEAN", "boolean": true } }, { "name": "isIgnoreCarriage", "value": { "type": "BOOLEAN", "boolean": false } } ], "value": { "type": "CONDITIONAL", "conditionalName": "stringVariable", "packageName": "String" } } ] } ], "attributes": [ { "name": "title", "value": { "type": "STRING", "string": "1:判斷需取得完成或失敗收件人" } } ] }, { "uid": "765cc618-60f6-4c99-aa09-41587770e548", "commandName": "step", "packageName": "Step", "disabled": false, "children": [ { "uid": "64a1400c-802f-42e0-8919-b34a555e2408", "commandName": "GetSingleCell", "packageName": "Excel_MS", "disabled": false, "attributes": [ { "name": "session", "value": { "type": "SESSION", "sessionName": { "type": "STRING", "string": "Email Config" } } }, { "name": "activeCell", "value": { "type": "STRING", "string": "false" } }, { "name": "cell", "value": { "type": "STRING", "string": "C2" } }, { "name": "readOption", "value": { "type": "STRING", "string": "READ_CELL_VALUE" } }, { "name": "readOption_readCellValue_Help", "value": { "type": "STRING" } } ], "returnTo": { "type": "VARIABLE", "variableName": "sPrefix" } }, { "uid": "a7f93eed-6554-42bb-a5a1-397064778e2c", "commandName": "loop.commands.start", "packageName": "Loop", "disabled": false, "children": [ { "uid": "41052b43-261a-4c28-ba8a-5c65244a475c", "commandName": "if", "packageName": "If", "disabled": false, "children": [ { "uid": "f429f0ae-e41e-40c5-a2ac-ddf57f84c686", "commandName": "assign", "packageName": "String", "disabled": false, "attributes": [ { "name": "sourceString", "value": { "type": "STRING", "expression": "$sRecipient$;$rGet_Email_Info[0]$" } } ], "returnTo": { "type": "VARIABLE", "variableName": "sRecipient" } } ], "branches": [], "attributes": [ { "name": "condition", "attributes": [ { "name": "variable", "value": { "type": "STRING", "expression": "$rGet_Email_Info[0]$" } }, { "name": "operator", "value": { "type": "STRING", "string": "NEQ" } }, { "name": "value", "value": { "type": "STRING", "string": "" } }, { "name": "matchCase", "value": { "type": "BOOLEAN", "boolean": true } }, { "name": "isIgnoreCarriage", "value": { "type": "BOOLEAN", "boolean": false } } ], "value": { "type": "CONDITIONAL", "conditionalName": "stringVariable", "packageName": "String" } } ] } ], "attributes": [ { "name": "loopType", "value": { "type": "STRING", "string": "ITERATOR" } }, { "name": "iterator", "returnTo": { "type": "VARIABLE", "variableName": "rGet_Email_Info" }, "attributes": [ { "name": "session", "value": { "type": "SESSION", "sessionName": { "type": "STRING", "string": "Email Config" } } }, { "name": "loopSelection", "value": { "type": "STRING", "string": "ALL_ROWS" } }, { "name": "readOption", "value": { "type": "STRING", "string": "READ_CELL_VALUE" } }, { "name": "readOption_readCellValue_Help", "value": { "type": "STRING" } } ], "value": { "type": "ITERATOR", "iteratorName": "loop.iterators.excel", "packageName": "Excel_MS" } } ] }, { "uid": "4c7e0009-3e80-420c-bf95-87bd08d53d41", "commandName": "loop.commands.start", "packageName": "Loop", "disabled": false, "children": [ { "uid": "cdc0133d-96ea-426c-a1ec-45c944727e74", "commandName": "if", "packageName": "If", "disabled": false, "children": [ { "uid": "654cda9c-a1be-41ad-81b2-271025dcd87f", "commandName": "assign", "packageName": "String", "disabled": false, "attributes": [ { "name": "sourceString", "value": { "type": "STRING", "expression": "$sCc_Group$;$rGet_Email_Info[1]$" } } ], "returnTo": { "type": "VARIABLE", "variableName": "sCc_Group" } } ], "branches": [], "attributes": [ { "name": "condition", "attributes": [ { "name": "variable", "value": { "type": "STRING", "expression": "$rGet_Email_Info[1]$" } }, { "name": "operator", "value": { "type": "STRING", "string": "NEQ" } }, { "name": "value", "value": { "type": "STRING", "string": "" } }, { "name": "matchCase", "value": { "type": "BOOLEAN", "boolean": true } }, { "name": "isIgnoreCarriage", "value": { "type": "BOOLEAN", "boolean": false } } ], "value": { "type": "CONDITIONAL", "conditionalName": "stringVariable", "packageName": "String" } } ] } ], "attributes": [ { "name": "loopType", "value": { "type": "STRING", "string": "ITERATOR" } }, { "name": "iterator", "returnTo": { "type": "VARIABLE", "variableName": "rGet_Email_Info" }, "attributes": [ { "name": "session", "value": { "type": "SESSION", "sessionName": { "type": "STRING", "string": "Email Config" } } }, { "name": "loopSelection", "value": { "type": "STRING", "string": "ALL_ROWS" } }, { "name": "readOption", "value": { "type": "STRING", "string": "READ_CELL_VALUE" } }, { "name": "readOption_readCellValue_Help", "value": { "type": "STRING" } } ], "value": { "type": "ITERATOR", "iteratorName": "loop.iterators.excel", "packageName": "Excel_MS" } } ] }, { "uid": "640a0a89-0252-4dbb-9a92-cb667d584a12", "commandName": "beforeAfter", "packageName": "String", "disabled": false, "attributes": [ { "name": "sourceString", "value": { "type": "STRING", "expression": "$sRecipient$" } }, { "name": "getCharacters", "value": { "type": "STRING", "string": "BEFORE" } }, { "name": "beforeString", "value": { "type": "STRING", "string": ";" } }, { "name": "beforeOccurrence", "value": { "type": "NUMBER", "number": "1" } }, { "name": "ifNoMatchFound", "value": { "type": "STRING", "string": "EMPTY" } }, { "name": "noOfCharsToGet", "value": { "type": "STRING", "string": "ALL" } }, { "name": "trimSpaces", "value": { "type": "BOOLEAN", "boolean": true } }, { "name": "removeEnter", "value": { "type": "BOOLEAN", "boolean": true } } ], "returnTo": { "type": "VARIABLE", "variableName": "sRecipient" } }, { "uid": "dc6fc20c-793b-421b-86ba-69355b8fee9b", "commandName": "beforeAfter", "packageName": "String", "disabled": false, "attributes": [ { "name": "sourceString", "value": { "type": "STRING", "expression": "$sCc_Group$" } }, { "name": "getCharacters", "value": { "type": "STRING", "string": "BEFORE" } }, { "name": "beforeString", "value": { "type": "STRING", "string": ";" } }, { "name": "beforeOccurrence", "value": { "type": "NUMBER", "number": "1" } }, { "name": "ifNoMatchFound", "value": { "type": "STRING", "string": "EMPTY" } }, { "name": "noOfCharsToGet", "value": { "type": "STRING", "string": "ALL" } }, { "name": "trimSpaces", "value": { "type": "BOOLEAN", "boolean": true } }, { "name": "removeEnter", "value": { "type": "BOOLEAN", "boolean": true } } ], "returnTo": { "type": "VARIABLE", "variableName": "sCc_Group" } }, { "uid": "f57be4d7-2fd2-4fc7-9319-2a5d7d9a36f7", "commandName": "sendMail", "packageName": "Email", "disabled": false, "attributes": [ { "name": "toAddress", "value": { "type": "STRING", "expression": "$sRecipient$" } }, { "name": "cc", "value": { "type": "STRING", "expression": "$sCc_Group$" } }, { "name": "bcc", "value": { "type": "STRING", "string": "" } }, { "name": "subject", "value": { "type": "STRING", "expression": "$sPrefix$ - $sSubject$" } }, { "name": "attachmentsFilePath", "value": { "type": "FILE", "expression": "file://$sAttechment$" } }, { "name": "ensureAttachmentsExist", "value": { "type": "BOOLEAN", "boolean": false } }, { "name": "bodyFormat", "value": { "type": "STRING", "string": "HTML" } }, { "name": "message", "value": { "type": "STRING", "expression": "$sEmail_Message$" } }, { "name": "goGreen", "value": { "type": "BOOLEAN", "boolean": false } }, { "name": "serverType", "value": { "type": "STRING", "string": "OUTLOOK" } } ] }, { "uid": "569bc7ed-3eaf-4ad3-94ab-36b401a87687", "commandName": "CloseSpreadsheet", "packageName": "Excel_MS", "disabled": false, "attributes": [ { "name": "session", "value": { "type": "SESSION", "sessionName": { "type": "STRING", "string": "Email Config" } } }, { "name": "isSave", "value": { "type": "BOOLEAN", "boolean": true } } ] }, { "uid": "d7bb895d-2bef-4a1a-90b0-3040883e2e14", "commandName": "delay", "packageName": "Delay", "disabled": false, "attributes": [ { "name": "delayType", "value": { "type": "STRING", "string": "REGULAR" } }, { "name": "delayTime", "value": { "type": "NUMBER", "number": "60" } }, { "name": "timeUnit", "value": { "type": "STRING", "string": "SECONDS" } } ] } ], "attributes": [ { "name": "title", "value": { "type": "STRING", "string": "2:取得收件人並寄出信件" } } ] } ], "branches": [ { "uid": "c95b4ff0-05e4-4872-810c-77de9ee91b03", "commandName": "catch", "packageName": "ErrorHandler", "disabled": false, "children": [ { "uid": "3a246d3a-c827-429d-a7af-f9f725858d6b", "commandName": "toString", "packageName": "Datetime", "disabled": false, "attributes": [ { "name": "source", "value": { "type": "VARIABLE", "packageName": "System", "variableName": "Date" } }, { "name": "selectPattern", "value": { "type": "STRING", "string": "CUSTOM" } }, { "name": "patternInput", "value": { "type": "STRING", "string": "yyyyMMdd_HHmmSS" } } ], "returnTo": { "type": "VARIABLE", "variableName": "sTimeStamp" } }, { "uid": "bd3915ce-a105-4530-b110-38cfd83cbf45", "commandName": "toString", "packageName": "Number", "disabled": false, "attributes": [ { "name": "input", "value": { "type": "NUMBER", "expression": "$nErrorLine$" } }, { "name": "numFormatDigits", "value": { "type": "NUMBER", "number": "0" } } ], "returnTo": { "type": "VARIABLE", "variableName": "sErrorLine" } }, { "uid": "41f18175-55bb-40ba-bff7-4fd9d3d82aed", "commandName": "assign", "packageName": "String", "disabled": false, "attributes": [ { "name": "sourceString", "value": { "type": "STRING", "expression": "$sErrorLine$:$sErrorMessage$" } } ], "returnTo": { "type": "VARIABLE", "variableName": "sErrorMessage" } }, { "uid": "ea11d681-3f54-4627-857c-0e734e68b650", "commandName": "captureWindow", "packageName": "Screen", "disabled": false, "attributes": [ { "name": "windowTitle", "value": { "type": "WINDOW", "window": { "type": "WINDOW", "presetType": "CURRENTLY_ACTIVE" } } }, { "name": "filePath", "value": { "type": "FILE", "expression": "file://$dFolder{sErrorSnapshot}$/$sTimeStamp$_Send%20Email.jpeg" } }, { "name": "isOverwriteFile", "value": { "type": "BOOLEAN", "boolean": false } } ] }, { "uid": "b0f069ec-cdf5-4a9e-8659-41c92c50362f", "commandName": "logToFile", "packageName": "LogToFile", "disabled": false, "attributes": [ { "name": "filePath", "value": { "type": "FILE", "expression": "file://$dFolder{sErrorLog}$/$sTimeStamp$_Check%20Files%20and%20Check.txt" } }, { "name": "logContent", "value": { "type": "STRING", "expression": "$sErrorMessage$" } }, { "name": "appendTimestamp", "value": { "type": "BOOLEAN", "boolean": false } }, { "name": "logOption", "value": { "type": "STRING", "string": "APPEND_FILE" } }, { "name": "encodingValue", "value": { "type": "STRING", "string": "ANSI" } } ] }, { "uid": "8072d185-5b98-4627-8b72-0893094ae34b", "commandName": "assign", "packageName": "String", "disabled": false, "attributes": [ { "name": "sourceString", "value": { "type": "STRING", "expression": "FAILED ($sErrorMessage$)" } } ], "returnTo": { "type": "VARIABLE", "variableName": "sModuleStatus" } } ], "attributes": [ { "name": "exceptionType", "value": { "type": "EXCEPTION", "exceptionName": "BotException", "packageName": "ErrorHandler" } } ], "returns": { "errorMessage": { "type": "VARIABLE", "variableName": "sErrorMessage" }, "errorLineNumber": { "type": "VARIABLE", "variableName": "nErrorLine" } } } ] } ], "variables": [ { "name": "prompt-assignment", "description": "A variable you can use for assignments", "type": "STRING", "subtype": "UNDEFINED", "readOnly": false, "input": false, "output": false }, { "name": "sTimeStamp", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": false, "subtype": "UNDEFINED", "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sErrorLine", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": true, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "nErrorLine", "description": "", "type": "NUMBER", "readOnly": false, "input": false, "output": false, "defaultValue": { "type": "NUMBER", "number": "0" } }, { "name": "sErrorMessage", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": true, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "dFolder", "description": "", "type": "DICTIONARY", "readOnly": false, "input": true, "output": false, "subtype": "STRING", "defaultValue": { "type": "DICTIONARY", "dictionary": [] } }, { "name": "sModuleStatus", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": true, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sTag", "description": "", "type": "STRING", "readOnly": false, "input": true, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sSubject", "description": "", "type": "STRING", "readOnly": false, "input": true, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sEmail_Message", "description": "", "type": "STRING", "readOnly": false, "input": true, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sAttechment", "description": "", "type": "STRING", "readOnly": false, "input": true, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sEmailConfig_Path", "description": "", "type": "STRING", "readOnly": false, "input": true, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sRecipient", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sCc_Group", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sPrefix", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "rGet_Email_Info", "description": "", "type": "RECORD", "readOnly": false, "input": false, "output": false, "subtype": "UNDEFINED", "defaultValue": { "type": "RECORD", "record": { "schema": [], "values": [] } } }, { "name": "sFrom_Address", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sEmail_Server_Host", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "nEmail_Server_Port", "description": "", "type": "NUMBER", "readOnly": false, "input": false, "output": false, "defaultValue": { "type": "NUMBER", "number": "0" } }, { "name": "sPassword", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sUsername", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": false, "defaultValue": { "type": "STRING", "string": "" } }, { "name": "sEmail_Server_Port", "description": "", "type": "STRING", "readOnly": false, "input": false, "output": false, "subtype": "UNDEFINED", "defaultValue": { "type": "STRING", "string": "" } } ], "breakpoints": [], "packages": [ { "name": "Datetime", "version": "2.2.0-20201014-042531" }, { "name": "Datetime", "version": "2.2.0-20201014-042531" }, { "name": "Delay", "version": "2.2.0-20201014-042532" }, { "name": "Delay", "version": "2.2.0-20201014-042532" }, { "name": "Email", "version": "3.1.0-20201104-062204" }, { "name": "Email", "version": "3.1.0-20201104-062204" }, { "name": "ErrorHandler", "version": "2.2.0-20201014-042541" }, { "name": "ErrorHandler", "version": "2.2.0-20201014-042541" }, { "name": "Excel_MS", "version": "6.3.0-20211028-055115" }, { "name": "Excel_MS", "version": "6.3.0-20211028-055115" }, { "name": "If", "version": "2.1.0-20200921-085758" }, { "name": "If", "version": "2.1.0-20200921-085758" }, { "name": "LogToFile", "version": "2.2.0-20201014-042806" }, { "name": "LogToFile", "version": "2.2.0-20201014-042806" }, { "name": "Loop", "version": "2.1.0-20201014-042808" }, { "name": "Loop", "version": "2.1.0-20201014-042808" }, { "name": "Number", "version": "2.1.0-20201014-042823" }, { "name": "Number", "version": "2.1.0-20201014-042823" }, { "name": "Screen", "version": "2.1.0-20201014-043037" }, { "name": "Screen", "version": "2.1.0-20201014-043037" }, { "name": "Step", "version": "2.0.0-20201023-202658" }, { "name": "Step", "version": "2.0.0-20201023-202658" }, { "name": "String", "version": "3.1.0-20201014-043052" }, { "name": "String", "version": "3.1.0-20201014-043052" }, { "name": "System", "version": "3.0.0-20200921-090225" }, { "name": "System", "version": "3.0.0-20200921-090225" } ], "migrationJournalReviewIds": [], "workItemTemplateName": null, "properties": { "botCodeVersion": "1", "improvedNumberSupport": false, "timeout": "0s", "automationPriority": "PRIORITY_MEDIUM" } } ' # Print the match result str.scan(re) do |match| puts match.to_s end

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html