Regular Expressions 101

Save & Share

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

/
/
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)^(?<parameter>[^:]+)\:\s*(?:(?<value>[A-Za-z]+\:\s*[^>]+))\s*(?<description>.*)" Local $sString = "pts_time: PTS: 1741047514> Time: 19345 sec > (hh:mm:ss.ms) 05:22:24.972" & @CRLF & _ "pts_time: PTS: 1741047514 [0x67C646DA] > Time: 19345 sec > (hh:mm:ss.ms) 05:22:24.972" & @CRLF & _ "private_indicator: '0' reserved: '11'" & @CRLF & _ "section_length: 0x39 (57) protocol_version: 0" & @CRLF & _ "encrypted_packet: 0 no part of this message is encrypted" & @CRLF & _ "encryption_algorithm: 0 No encryption" & @CRLF & _ "pts_adjustment: 0xFFFF7F18 (33000) > Time: 95443.4 sec > (hh:mm:ss.ms) 26:30:43.351" & @CRLF & _ "cw_index: 0x00 (0) tier: 0x0FFF (4095)" & @CRLF & _ "splice_command_length: 0x0005 (5) splice_command_type: 0x06 (6) time_signal [] time_signal: > Time: 19345 sec > (hh:mm:ss.ms) 05:22:24.972" & @CRLF & _ "time_specified_flag: 1 presence of the pts_time field" & @CRLF & _ "reserved: 0x3F (63) descriptor_loop_length: 35 [] Descriptors: [] segmentation_descriptor (0x02): Content Identification (0x01)" & @CRLF & _ "descriptor_tag: 0x02 (2) descriptor_length: 0x21 (33)" & @CRLF & _ "identifier: 0x43554549 (CUEI) segmentation_event_id: 0x00000001 (1)" & @CRLF & _ "segmentation_event_cancel_indicator: '0' a previously sent segmentation event, identified by segmentation_event_id, has NOT been cancelled" & @CRLF & _ "reserved: 0x7F (127) program_segmentation_flag: '1' the message refers to a Program Segmentation Point and that the mode is the Program Segmentation Mode whereby all PIDs/components of the program are to be segmented" & @CRLF & _ "segmentation_duration_flag: '0' No presence of segmentation_duration field" & @CRLF & _ "delivery_not_restricted_flag: '1' the next five bits are reserved" & @CRLF & _ "reserved: 0x1F (31) segmentation_upid_type: 0x01 (1) Deprecated: use type 0x0C; The segmentation_upid does not follow a standard naming scheme." & @CRLF & _ "segmentation_upid_length: 0x12 (18) segmentation_type_id: 0x01 (1) Content Identification" & @CRLF & _ "segment_num: 0x01 (1) segments_expected: 0x01 (1)" & @CRLF & _ "CRC_32: 0x46D15AF3 CRC OK" & @CRLF & _ "" & @CRLF & _ "// try this one first" & @CRLF & _ "// (a) ^(?<parameter>[^:]+)\:\s*(?:(?<value>[A-Za-z]+\:\s*[^>]+))" & @CRLF & _ "// (b) ^(?<parameter>[^:]+)\:\s*(?:(?<value>[A-Za-z]+\:\s*[^>]+))\s*(?<description>.*)" & @CRLF & _ "" & @CRLF & _ "// in case of no match of the above one use the second" & @CRLF & _ "// (a) ^(?<parameter>[^:]+):\s*(?<value>[\w']+(?:\s*\([^)]*\))*)" & @CRLF & _ "// (b) ^(?<parameter>[^:]+):\s*(?<value>[\w']+(?:\s*\([^)]*\))*)\s*(?<description>.*)" & @CRLF & _ "" & @CRLF & _ "// substitution:" & @CRLF & _ "// ["$1", "$2", "$3"]" & @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