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 (4)

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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

`
`
gm

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 = "(?m).*\((.|\n)+\)\s*\{" Local $sString = "# @summary Manages the puppeteer monitor service." & @CRLF & _ "# " & @CRLF & _ "# @param logon_domain" & @CRLF & _ "# The service will logon using this domain. Specify '.' for a local account." & @CRLF & _ "#" & @CRLF & _ "# @param logon_name" & @CRLF & _ "# The service will logon using this user name." & @CRLF & _ "#" & @CRLF & _ "# @param logon_password" & @CRLF & _ "# The service will logon using this password." & @CRLF & _ "#" & @CRLF & _ "# @param ensure" & @CRLF & _ "# Whether or not install the puppeteermon service." & @CRLF & _ "#" & @CRLF & _ "# @param source" & @CRLF & _ "# Where to obtain the puppeteermon service executable from." & @CRLF & _ "#" & @CRLF & _ "# @param state" & @CRLF & _ "# Ensure the puppeteermon service is in the given `state`." & @CRLF & _ "#" & @CRLF & _ "# @param startup" & @CRLF & _ "# How to start the puppeteermon service." & @CRLF & _ "#" & @CRLF & _ "# @param version" & @CRLF & _ "# The version of the puppeteermon service that should be installed." & @CRLF & _ "#" & @CRLF & _ "class profile::ct::puppeteermon(" & @CRLF & _ " String $logon_domain = "${hiera('builder_domain', '.')}"," & @CRLF & _ " String $logon_name = "${hiera('builder_user', 'SYSTEM')}"," & @CRLF & _ " String $logon_password = "${hiera('builder_passwd', '')}"," & @CRLF & _ " String $cooldown = '10m'," & @CRLF & _ " String $min_exec_time = '1m15s'," & @CRLF & _ " Enum[absent, present] $ensure = present," & @CRLF & _ " String $source = 'https://repo.ct.activision.com/repository/puppet/puppeteermon/<%= ::osfamily %>/puppeteermon-<%= version %>'," & @CRLF & _ " Enum['running', 'stopped'] $state = 'running'," & @CRLF & _ "" & @CRLF & _ " Enum['automatic', 'manual', 'disabled']" & @CRLF & _ " $startup = 'automatic'," & @CRLF & _ "" & @CRLF & _ " String $version = '2.0.11'," & @CRLF & _ ") {" & @CRLF & _ " include profile::ct::puppeteer" & @CRLF & _ "" & @CRLF & _ " if $::osfamily == 'windows' {" & @CRLF & _ " # Non-configurable class parameters" & @CRLF & _ " $basedir = 'C:/ProgramData/puppeteermon'" & @CRLF & _ " $os_source = regsubst($source, '<%= ::osfamily %>', 'windows', 'G')" & @CRLF & _ " $puppeteer_os_source = regsubst($profile::ct::puppeteer::source, '<%= ::osfamily %>', 'windows', 'G')" & @CRLF & _ " $puppeteer_fetch_source = regsubst($puppeteer_os_source, '<%= version %>', "${profile::ct::puppeteer::version}.exe", 'G')" & @CRLF & _ " $puppeteer_recovery_source = regsubst($puppeteer_os_source, '<%= version %>', 'recovery.exe', 'G')" & @CRLF & _ "" & @CRLF & _ " profile::ct::puppeteer::config { "${profile::ct::puppeteer::basedir}/puppeteer.conf":" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " compass_master_url => $profile::ct::puppeteer::compass_master_url," & @CRLF & _ " runinterval => $profile::ct::puppeteer::runinterval," & @CRLF & _ " splay => $profile::ct::puppeteer::splay," & @CRLF & _ " version => $profile::ct::puppeteer::version," & @CRLF & _ " }" & @CRLF & _ " -> profile::ct::puppeteermon::config { "${basedir}/puppeteermon.conf":" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " cooldown => $cooldown," & @CRLF & _ " fetch_url => $puppeteer_fetch_source," & @CRLF & _ " download_dir => "${profile::ct::puppeteer::basedir}/fetch"," & @CRLF & _ " command => "${profile::ct::puppeteer::basedir}/running/puppeteer.exe"," & @CRLF & _ " }" & @CRLF & _ " profile::ct::puppeteer::config_new { "${profile::ct::puppeteer::basedir}/puppeteer.yaml":" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " compass_master_url => $profile::ct::puppeteer::compass_master_url," & @CRLF & _ " compass_polling_interval => $profile::ct::puppeteer::compass_polling_interval," & @CRLF & _ " runinterval => $profile::ct::puppeteer::runinterval," & @CRLF & _ " last_run_summary => $profile::ct::puppeteer::last_run_summary," & @CRLF & _ " splay => $profile::ct::puppeteer::splay," & @CRLF & _ " version => $profile::ct::puppeteer::version," & @CRLF & _ " agent_config_platform => $profile::ct::puppeteer::agent_config_platform," & @CRLF & _ " }" & @CRLF & _ " -> profile::ct::puppeteermon::config_new { "${basedir}/puppeteermon.yaml":" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " cooldown => $cooldown," & @CRLF & _ " fetch_url => $puppeteer_fetch_source," & @CRLF & _ " recovery_url => $puppeteer_recovery_source," & @CRLF & _ " download_dir => "${profile::ct::puppeteer::basedir}/stage"," & @CRLF & _ " command => "${profile::ct::puppeteer::basedir}/running/puppeteer.exe"," & @CRLF & _ " min_exec_time => $min_exec_time" & @CRLF & _ " }" & @CRLF & _ " -> wservice { 'puppeteermon':" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " state => $state," & @CRLF & _ " startup => $startup," & @CRLF & _ " source => regsubst($os_source, '<%= version %>', "${version}.tar.gz", 'G')," & @CRLF & _ " version => $version," & @CRLF & _ " path => "${basedir}/puppeteermon.exe"," & @CRLF & _ " account => "${logon_domain}\\${logon_name}"," & @CRLF & _ " password => $logon_password," & @CRLF & _ " registercmd => ['<%= path %>', 'install']," & @CRLF & _ " unregistercmd => ['<%= path %>', 'uninstall']," & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " if $ensure == present {" & @CRLF & _ " $enable = $startup ? { 'automatic' => 'true', 'manual' => 'manual', default => 'false' }" & @CRLF & _ " service { 'puppeteermon':" & @CRLF & _ " ensure => $state," & @CRLF & _ " enable => $enable," & @CRLF & _ " require => Wservice['puppeteermon']" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " } elsif $::osfamily == 'Darwin' {" & @CRLF & _ " # Non-configurable class parameters" & @CRLF & _ " $basedir = '/opt/puppeteermon'" & @CRLF & _ " $os_source = regsubst($source, '<%= ::osfamily %>', 'darwin', 'G')" & @CRLF & _ " $puppeteer_os_source = regsubst($profile::ct::puppeteer::source, '<%= ::osfamily %>', 'darwin', 'G')" & @CRLF & _ " $puppeteer_fetch_source = regsubst($puppeteer_os_source, '<%= version %>', $profile::ct::puppeteer::version, 'G')" & @CRLF & _ " $puppeteer_recovery_source = regsubst($puppeteer_os_source, '<%= version %>', 'recovery', 'G')" & @CRLF & _ "" & @CRLF & _ " profile::ct::puppeteer::config_new { "${profile::ct::puppeteer::basedir}/puppeteer.yaml":" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " compass_master_url => $profile::ct::puppeteer::compass_master_url," & @CRLF & _ " compass_polling_interval => $profile::ct::puppeteer::compass_polling_interval," & @CRLF & _ " runinterval => $profile::ct::puppeteer::runinterval," & @CRLF & _ " last_run_summary => $profile::ct::puppeteer::last_run_summary," & @CRLF & _ " splay => $profile::ct::puppeteer::splay," & @CRLF & _ " version => $profile::ct::puppeteer::version," & @CRLF & _ " agent_config_platform => $profile::ct::puppeteer::agent_config_platform," & @CRLF & _ " }" & @CRLF & _ " -> profile::ct::puppeteermon::config_new { "${basedir}/puppeteermon.yaml":" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " cooldown => $cooldown," & @CRLF & _ " fetch_url => $puppeteer_fetch_source," & @CRLF & _ " recovery_url => $puppeteer_recovery_source," & @CRLF & _ " download_dir => "${profile::ct::puppeteer::basedir}/stage"," & @CRLF & _ " command => "${profile::ct::puppeteer::basedir}/running/puppeteer"," & @CRLF & _ " min_exec_time => $min_exec_time" & @CRLF & _ " }" & @CRLF & _ " -> puppeteermon { '/opt/puppeteermon/puppeteermon':" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " version => $version," & @CRLF & _ " source => regsubst($os_source, '<%= version %>', $version, 'G')," & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " if $ensure == present {" & @CRLF & _ " $enable = $startup ? {'automatic' => 'true', 'manual' => 'manual', default => 'false' }" & @CRLF & _ " service { 'puppeteermon':" & @CRLF & _ " ensure => $state," & @CRLF & _ " enable => $enable," & @CRLF & _ " provider => 'launchd'," & @CRLF & _ " require => Puppeteermon['/opt/puppeteermon/puppeteermon']" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " } else {" & @CRLF & _ " # Non-configurable class parameters" & @CRLF & _ " $basedir = '/opt/puppeteermon'" & @CRLF & _ " $os_source = regsubst($source, '<%= ::osfamily %>', 'linux', 'G')" & @CRLF & _ " $puppeteer_os_source = regsubst($profile::ct::puppeteer::source, '<%= ::osfamily %>', 'linux', 'G')" & @CRLF & _ " $puppeteer_fetch_source = regsubst($puppeteer_os_source, '<%= version %>', $profile::ct::puppeteer::version, 'G')" & @CRLF & _ " $puppeteer_recovery_source = regsubst($puppeteer_os_source, '<%= version %>', 'recovery', 'G')" & @CRLF & _ "" & @CRLF & _ " profile::ct::puppeteer::config_new { "${profile::ct::puppeteer::basedir}/puppeteer.yaml":" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " compass_master_url => $profile::ct::puppeteer::compass_master_url," & @CRLF & _ " compass_polling_interval => $profile::ct::puppeteer::compass_polling_interval," & @CRLF & _ " runinterval => $profile::ct::puppeteer::runinterval," & @CRLF & _ " last_run_summary => $profile::ct::puppeteer::last_run_summary," & @CRLF & _ " splay => $profile::ct::puppeteer::splay," & @CRLF & _ " version => $profile::ct::puppeteer::version," & @CRLF & _ " agent_config_platform => $profile::ct::puppeteer::agent_config_platform," & @CRLF & _ " }" & @CRLF & _ " -> profile::ct::puppeteermon::config_new { "${basedir}/puppeteermon.yaml":" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " cooldown => $cooldown," & @CRLF & _ " fetch_url => $puppeteer_fetch_source," & @CRLF & _ " recovery_url => $puppeteer_recovery_source," & @CRLF & _ " download_dir => "${profile::ct::puppeteer::basedir}/stage"," & @CRLF & _ " command => "${profile::ct::puppeteer::basedir}/running/puppeteer"," & @CRLF & _ " min_exec_time => $min_exec_time" & @CRLF & _ " }" & @CRLF & _ " -> puppeteermon { '/opt/puppeteermon/puppeteermon':" & @CRLF & _ " ensure => $ensure," & @CRLF & _ " version => $version," & @CRLF & _ " source => regsubst($os_source, '<%= version %>', $version, 'G')," & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " if $ensure == present {" & @CRLF & _ " $enable = $startup ? {'automatic' => 'true', 'manual' => 'manual', default => 'false' }" & @CRLF & _ " service { 'puppeteermon':" & @CRLF & _ " ensure => $state," & @CRLF & _ " enable => $enable," & @CRLF & _ " provider => 'systemd'," & @CRLF & _ " require => Puppeteermon['/opt/puppeteermon/puppeteermon']" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ "}" & @CRLF & _ "" 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