Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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

`
`
sg

Test String

Code Generator

Generated Code

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?s) *<hashTree>. *<JSONPathAssertion.*?</JSONPathAssertion>. *<hashTree/>. *</hashTree>." Local $sString = "<?xml version="1.0" encoding="UTF-8"?>" & @CRLF & _ "<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.1.1 r1855137">" & @CRLF & _ " <hashTree>" & @CRLF & _ " <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="test one" enabled="true">" & @CRLF & _ " <stringProp name="TestPlan.comments"></stringProp>" & @CRLF & _ " <boolProp name="TestPlan.functional_mode">false</boolProp>" & @CRLF & _ " <boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>" & @CRLF & _ " <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>" & @CRLF & _ " <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">" & @CRLF & _ " <collectionProp name="Arguments.arguments"/>" & @CRLF & _ " </elementProp>" & @CRLF & _ " <stringProp name="TestPlan.user_define_classpath"></stringProp>" & @CRLF & _ " </TestPlan>" & @CRLF & _ " <hashTree>" & @CRLF & _ " <com.blazemeter.jmeter.threads.concurrency.ConcurrencyThreadGroup guiclass="com.blazemeter.jmeter.threads.concurrency.ConcurrencyThreadGroupGui" testclass="com.blazemeter.jmeter.threads.concurrency.ConcurrencyThreadGroup" testname="Thread - main" enabled="true">" & @CRLF & _ " <elementProp name="ThreadGroup.main_controller" elementType="com.blazemeter.jmeter.control.VirtualUserController"/>" & @CRLF & _ " <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>" & @CRLF & _ " <stringProp name="TargetLevel">${__P(threads, 1)}</stringProp>" & @CRLF & _ " <stringProp name="RampUp">${__P(time, 1)}</stringProp>" & @CRLF & _ " <stringProp name="Steps">${__P(steps, 1)}</stringProp>" & @CRLF & _ " <stringProp name="Hold">${__P(hold, 3)}</stringProp>" & @CRLF & _ " <stringProp name="LogFilename"></stringProp>" & @CRLF & _ " <stringProp name="Iterations"></stringProp>" & @CRLF & _ " <stringProp name="Unit">M</stringProp>" & @CRLF & _ " </com.blazemeter.jmeter.threads.concurrency.ConcurrencyThreadGroup>" & @CRLF & _ " <hashTree>" & @CRLF & _ " <GenericController guiclass="LogicControllerGui" testclass="GenericController" testname="Simple Controller - main" enabled="true"/>" & @CRLF & _ " <hashTree>" & @CRLF & _ " <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="REQUEST1" enabled="true">" & @CRLF & _ " <boolProp name="HTTPSampler.postBodyRaw">true</boolProp>" & @CRLF & _ " <elementProp name="HTTPsampler.Arguments" elementType="Arguments">" & @CRLF & _ " <collectionProp name="Arguments.arguments">" & @CRLF & _ " <elementProp name="" elementType="HTTPArgument">" & @CRLF & _ " <boolProp name="HTTPArgument.always_encode">false</boolProp>" & @CRLF & _ " <stringProp name="Argument.value">{&#xd;" & @CRLF & _ " &quot;version&quot;: &quot;1.1&quot;,&#xd;" & @CRLF & _ " &quot;test&quot;: {&#xd;" & @CRLF & _ "}</stringProp>" & @CRLF & _ " <stringProp name="Argument.metadata">=</stringProp>" & @CRLF & _ " </elementProp>" & @CRLF & _ " </collectionProp>" & @CRLF & _ " </elementProp>" & @CRLF & _ " <stringProp name="HTTPSampler.domain"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.port"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.protocol"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.contentEncoding"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.path"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.method">POST</stringProp>" & @CRLF & _ " <boolProp name="HTTPSampler.follow_redirects">false</boolProp>" & @CRLF & _ " <boolProp name="HTTPSampler.auto_redirects">false</boolProp>" & @CRLF & _ " <boolProp name="HTTPSampler.use_keepalive">true</boolProp>" & @CRLF & _ " <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>" & @CRLF & _ " <stringProp name="HTTPSampler.embedded_url_re"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.connect_timeout"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.response_timeout"></stringProp>" & @CRLF & _ " </HTTPSamplerProxy>" & @CRLF & _ " <hashTree>" & @CRLF & _ " <JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="JSON Assertion" enabled="true">" & @CRLF & _ " <stringProp name="JSON_PATH">$.status</stringProp>" & @CRLF & _ " <stringProp name="EXPECTED_VALUE">ok</stringProp>" & @CRLF & _ " <boolProp name="JSONVALIDATION">true</boolProp>" & @CRLF & _ " <boolProp name="EXPECT_NULL">false</boolProp>" & @CRLF & _ " <boolProp name="INVERT">false</boolProp>" & @CRLF & _ " <boolProp name="ISREGEX">false</boolProp>" & @CRLF & _ " </JSONPathAssertion>" & @CRLF & _ " <hashTree/>" & @CRLF & _ " <JSR223PreProcessor guiclass="TestBeanGUI" testclass="JSR223PreProcessor" testname="JSR223 PreProcessor" enabled="true">" & @CRLF & _ " <stringProp name="cacheKey">true</stringProp>" & @CRLF & _ " <stringProp name="filename"></stringProp>" & @CRLF & _ " <stringProp name="parameters"></stringProp>" & @CRLF & _ " <stringProp name="script">// period in the past - year-month-day, set from properties in User Defined Variables" & @CRLF & _ "" & @CRLF & _ "import java.time.Instant;" & @CRLF & _ "import java.time.temporal.ChronoUnit;" & @CRLF & _ "import groovy.json.JsonOutput;" & @CRLF & _ "import org.apache.commons.lang.RandomStringUtils;</stringProp>" & @CRLF & _ " <stringProp name="scriptLanguage">groovy</stringProp>" & @CRLF & _ " </JSR223PreProcessor>" & @CRLF & _ " <hashTree/>" & @CRLF & _ " <JSR223PostProcessor guiclass="TestBeanGUI" testclass="JSR223PostProcessor" testname="JSR223 PostProcessor" enabled="true">" & @CRLF & _ " <stringProp name="cacheKey">true</stringProp>" & @CRLF & _ " <stringProp name="filename"></stringProp>" & @CRLF & _ " <stringProp name="parameters"></stringProp>" & @CRLF & _ " <stringProp name="script">import java.time.Instant;" & @CRLF & _ "import java.time.temporal.ChronoUnit;</stringProp>" & @CRLF & _ " <stringProp name="scriptLanguage">groovy</stringProp>" & @CRLF & _ " </JSR223PostProcessor>" & @CRLF & _ " <hashTree/>" & @CRLF & _ " </hashTree>" & @CRLF & _ " <IfController guiclass="IfControllerPanel" testclass="IfController" testname="If Controller" enabled="true">" & @CRLF & _ " <stringProp name="IfController.condition">${__groovy(${random_variable} == 1)}</stringProp>" & @CRLF & _ " <boolProp name="IfController.evaluateAll">false</boolProp>" & @CRLF & _ " <boolProp name="IfController.useExpression">true</boolProp>" & @CRLF & _ " </IfController>" & @CRLF & _ " <hashTree>" & @CRLF & _ " <RandomController guiclass="RandomControlGui" testclass="RandomController" testname="Random Controller" enabled="true">" & @CRLF & _ " <intProp name="InterleaveControl.style">1</intProp>" & @CRLF & _ " </RandomController>" & @CRLF & _ " <hashTree>" & @CRLF & _ " <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="REQUEST2" enabled="true">" & @CRLF & _ " <boolProp name="HTTPSampler.postBodyRaw">true</boolProp>" & @CRLF & _ " <elementProp name="HTTPsampler.Arguments" elementType="Arguments">" & @CRLF & _ " <collectionProp name="Arguments.arguments">" & @CRLF & _ " <elementProp name="" elementType="HTTPArgument">" & @CRLF & _ " <boolProp name="HTTPArgument.always_encode">false</boolProp>" & @CRLF & _ " <stringProp name="Argument.value">{&#xd;" & @CRLF & _ " &quot;version&quot;: &quot;1.1&quot;,&#xd;" & @CRLF & _ " &quot;test&quot;: {&#xd;" & @CRLF & _ "}</stringProp>" & @CRLF & _ " <stringProp name="Argument.metadata">=</stringProp>" & @CRLF & _ " </elementProp>" & @CRLF & _ " </collectionProp>" & @CRLF & _ " </elementProp>" & @CRLF & _ " <stringProp name="HTTPSampler.domain"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.port"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.protocol"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.contentEncoding"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.path"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.method">POST</stringProp>" & @CRLF & _ " <boolProp name="HTTPSampler.follow_redirects">false</boolProp>" & @CRLF & _ " <boolProp name="HTTPSampler.auto_redirects">false</boolProp>" & @CRLF & _ " <boolProp name="HTTPSampler.use_keepalive">true</boolProp>" & @CRLF & _ " <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>" & @CRLF & _ " <stringProp name="HTTPSampler.embedded_url_re"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.connect_timeout"></stringProp>" & @CRLF & _ " <stringProp name="HTTPSampler.response_timeout"></stringProp>" & @CRLF & _ " </HTTPSamplerProxy>" & @CRLF & _ " <hashTree>" & @CRLF & _ " <JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="JSON Assertion" enabled="true">" & @CRLF & _ " <stringProp name="JSON_PATH">$.status</stringProp>" & @CRLF & _ " <stringProp name="EXPECTED_VALUE">ok</stringProp>" & @CRLF & _ " <boolProp name="JSONVALIDATION">true</boolProp>" & @CRLF & _ " <boolProp name="EXPECT_NULL">false</boolProp>" & @CRLF & _ " <boolProp name="INVERT">false</boolProp>" & @CRLF & _ " <boolProp name="ISREGEX">false</boolProp>" & @CRLF & _ " </JSONPathAssertion>" & @CRLF & _ " <hashTree/>" & @CRLF & _ " </hashTree>" & @CRLF & _ " </hashTree>" & @CRLF & _ " </hashTree>" & @CRLF & _ " </hashTree>" & @CRLF & _ " </hashTree>" & @CRLF & _ " </hashTree>" & @CRLF & _ " </hashTree>" & @CRLF & _ "</jmeterTestPlan>" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "Result")

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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm