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

/
/
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)^(?:time=\"(?<longtime>\d{4}-\d{2}-\d{2}\D{1}\d{2}:\d{2}:\d{2}\+\d{2}:\d{2})\") (?:level=(?<level>(info|warn|error))) (?:msg=\"(?<msg>.*)\") (((?:duration=(?<duration>\d{1,9}.\d{1,9})) (?:gitaly_embedded=(?<gitaly_embedded>[^ ]+)) (?:method=(?<method>(POST|GET))))|((?:body="(?<body>.*)") (?<code>code=\d{3}) (?:method=(?<method2>(POST|GET)))|(?<command>command=".*"))|(?:key_id=key-(?<key_id>)\d{3})) (?:pid=(?<pid>\d{1,5})) (?:url=\"(((?<url>.*)\"))|(?:user="(?<user>.*)")|(?:public_key="(?<public_key>.*)"))" Local $sString = "time="2019-06-10T09:23:34+03:00" level=info msg="finished HTTP request" duration=0.02119909 gitaly_embedded=false method=POST pid=45053 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:34+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\"repository\":{\"storage_name\":\"default\",\"relative_path\":\"internet_platform/auto_tests.git\",\"git_object_directory\":\"\",\"git_alternate_object_directories\":[],\"gl_repository\":\"project-548\",\"gl_project_path\":\"internet_platform/auto_tests\"},\"gl_repository\":\"project-548\",\"gl_project_path\":\"internet_platform/auto_tests\",\"gl_id\":\"key-147\",\"gl_username\":\"Ext-Y.Korop\",\"git_config_options\":[],\"git_protocol\":null}" pid=45053 user="user with id key-147"" & @CRLF & _ "time="2019-06-10T09:23:38+03:00" level=info msg="finished HTTP request" duration=0.021129036 gitaly_embedded=false method=POST pid=45077 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:38+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\"repository\":{\"storage_name\":\"default\",\"relative_path\":\"erl-omsk/eps-storage-web.git\",\"git_object_directory\":\"\",\"git_alternate_object_directories\":[],\"gl_repository\":\"project-1375\",\"gl_project_path\":\"erl-omsk/eps-storage-web\"},\"gl_repository\":\"project-1375\",\"gl_project_path\":\"erl-omsk/eps-storage-web\",\"gl_id\":\"key-147\",\"gl_username\":\"Ext-Y.Korop\",\"git_config_options\":[],\"git_protocol\":null}" pid=45077 user="user with id key-147"" & @CRLF & _ "time="2019-06-10T09:23:42+03:00" level=info msg="finished HTTP request" duration=0.021581528 gitaly_embedded=false method=POST pid=45169 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:42+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\"repository\":{\"storage_name\":\"default\",\"relative_path\":\"erl-omsk/smev-fssp.git\",\"git_object_directory\":\"\",\"git_alternate_object_directories\":[],\"gl_repository\":\"project-63\",\"gl_project_path\":\"erl-omsk/smev-fssp\"},\"gl_repository\":\"project-63\",\"gl_project_path\":\"erl-omsk/smev-fssp\",\"gl_id\":\"key-147\",\"gl_username\":\"Ext-Y.Korop\",\"git_config_options\":[],\"git_protocol\":null}" pid=45169 user="user with id key-147"" & @CRLF & _ "time="2019-06-10T09:23:44+03:00" level=info msg="finished HTTP request" duration=0.022346368 gitaly_embedded=false method=POST pid=45236 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:44+03:00" level=error msg="Call failed" body="{\"status\":false,\"message\":\"Your account has been blocked.\"}" code=401 method=POST pid=45236 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:44+03:00" level=warn msg="Access denied" command="git-upload-pack 'kubernetes/heapster-k8s-config.git'" pid=45236 user="user with id key-18"" & @CRLF & _ "time="2019-06-10T09:23:46+03:00" level=info msg="finished HTTP request" duration=0.019885438 gitaly_embedded=false method=POST pid=45308 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:46+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\"repository\":{\"storage_name\":\"default\",\"relative_path\":\"erl-omsk/eps-mail-receiver.git\",\"git_object_directory\":\"\",\"git_alternate_object_directories\":[],\"gl_repository\":\"project-814\",\"gl_project_path\":\"erl-omsk/eps-mail-receiver\"},\"gl_repository\":\"project-814\",\"gl_project_path\":\"erl-omsk/eps-mail-receiver\",\"gl_id\":\"key-147\",\"gl_username\":\"Ext-Y.Korop\",\"git_config_options\":[],\"git_protocol\":null}" pid=45308 user="user with id key-147"" & @CRLF & _ "time="2019-06-10T09:23:51+03:00" level=info msg="finished HTTP request" duration=0.025155263 gitaly_embedded=false method=POST pid=45461 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:51+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\"repository\":{\"storage_name\":\"default\",\"relative_path\":\"erl-omsk/eps-api.git\",\"git_object_directory\":\"\",\"git_alternate_object_directories\":[],\"gl_repository\":\"project-906\",\"gl_project_path\":\"erl-omsk/eps-api\"},\"gl_repository\":\"project-906\",\"gl_project_path\":\"erl-omsk/eps-api\",\"gl_id\":\"key-147\",\"gl_username\":\"Ext-Y.Korop\",\"git_config_options\":[],\"git_protocol\":null}" pid=45461 user="user with id key-147"" & @CRLF & _ "time="2019-06-10T09:23:53+03:00" level=info msg="finished HTTP request" duration=0.0159927 gitaly_embedded=false method=POST pid=45550 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:53+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\"repository\":{\"storage_name\":\"default\",\"relative_path\":\"uksz/as-ss-stub.git\",\"git_object_directory\":\"\",\"git_alternate_object_directories\":[],\"gl_repository\":\"project-1644\",\"gl_project_path\":\"uksz/as-ss-stub\"},\"gl_repository\":\"project-1644\",\"gl_project_path\":\"uksz/as-ss-stub\",\"gl_id\":\"key-580\",\"gl_username\":\"Ext-A.P.Kosarenko\",\"git_config_options\":[],\"git_protocol\":null}" pid=45550 user="user with id key-580"" & @CRLF & _ "time="2019-06-10T09:23:54+03:00" level=info msg="finished HTTP request" duration=0.014709537 gitaly_embedded=false method=POST pid=45593 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:54+03:00" level=error msg="Call failed" body="{\"status\":false,\"message\":\"Your account has been blocked.\"}" code=401 method=POST pid=45593 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:54+03:00" level=warn msg="Access denied" command="git-upload-pack 'Docker/example.git'" pid=45593 user="user with id key-18"" & @CRLF & _ "time="2019-06-10T09:23:55+03:00" level=info msg="finished HTTP request" duration=0.020508204 gitaly_embedded=false method=POST pid=45669 url="http://127.0.0.1:8080/api/v4/internal/allowed"" & @CRLF & _ "time="2019-06-10T09:23:55+03:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\"repository\":{\"storage_name\":\"default\",\"relative_path\":\"erl-omsk/eps-digital-signature.git\",\"git_object_directory\":\"\",\"git_alternate_object_directories\":[],\"gl_repository\":\"project-785\",\"gl_project_path\":\"erl-omsk/eps-digital-signature\"},\"gl_repository\":\"project-785\",\"gl_project_path\":\"erl-omsk/eps-digital-signature\",\"gl_id\":\"key-147\",\"gl_username\":\"Ext-Y.Korop\",\"git_config_options\":[],\"git_protocol\":null}" pid=45669 user="user with id key-147"" 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