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

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?m)(?P<name>^[A-Za-z\/()\'’, -]+)(\s\d{2}|\s[1-9])?\s?(\s(?P<d1>-[\d,]+|[\d,.]+)\s(?P<d2>-[\d,]+|[\d,.]+))" Local $sString = "38" & @CRLF & _ "Frontken Corporation Berhad -651020-T Annual Report 2010" & @CRLF & _ "STATEMENTS OF FINANCIAL POSITION" & @CRLF & _ "AS OF 31 DECEMBER 2010" & @CRLF & _ "The Group The Company" & @CRLF & _ "Restated Restated" & @CRLF & _ "RM RM RM RM RM" & @CRLF & _ "ASSETS" & @CRLF & _ "Non-Current Assets" & @CRLF & _ "Property, plant and equipment 10 178,405,029 116,971,685 112,532,450 190,014 100,755" & @CRLF & _ "Prepaid lease payments 11 0 0 0 0 0" & @CRLF & _ "Investment in subsidiaries 12 0 0 0 68,192,335 30,903,191" & @CRLF & _ "Investment in associates 13 4,494,255 46,538,503 48,192,140 0 22,955,162" & @CRLF & _ "Goodwill on consolidation 14 28,311,674 4,724,073 3,749,020 0 0" & @CRLF & _ "Intangible assets 15 0 0 0 0 0" & @CRLF & _ "Deferred tax assets 16 352,360 0 0 0 0" & @CRLF & _ "Current Assets" & @CRLF & _ "Inventories 17 10,431,408 8,925,542 9,044,623 0 0" & @CRLF & _ "Amount due from contract customers 0 0 668,875 0 0" & @CRLF & _ "Trade receivables 18 67,337,237 36,900,201 41,323,668 0 0" & @CRLF & _ "Other receivables and prepaid expenses 18 5,125,566 5,285,410 10,169,824 27,841 43,427" & @CRLF & _ "Amount owing by subsidiaries 19 0 0 0 45,680,029 43,607,599" & @CRLF & _ "Amount owing by associates 13 4,534,039 2,098,465 3,500,059 0 0" & @CRLF & _ "Fixed deposits with licensed banks 12,684,190 781,627 758,232 12,000,000 0" & @CRLF & _ "Cash and bank balances 21,515,759 12,770,709 10,440,412 1,474,363 200,943" & @CRLF & _ "EQUITY AND LIABILITIES" & @CRLF & _ "Equity" & @CRLF & _ "Share capital 20 101,140,816 72,243,440 69,977,040 101,140,816 72,243,440" & @CRLF & _ "Reserves 21 75,102,500 63,104,940 51,689,521 9,444,784 6,607,044" & @CRLF & _ "Minority interests 25,901,844 182,232 651,874 0 0" & @CRLF & _ "Non-Current Liabilities" & @CRLF & _ "Term loans 22 48,314,340 25,265,019 33,200,474 0 0" & @CRLF & _ "Hire purchase payables 23 9,867,784 14,596,712 12,091,335 0 0" & @CRLF & _ "Deferred tax liabilities 16 4,389,835 3,789,267 3,466,075 0 0" & @CRLF & _ "Frontken Corporation Berhad -651020-T Annual Report 2010" & @CRLF & _ "STATEMENTS OF FINANCIAL POSITION" & @CRLF & _ "AS OF 31 DECEMBER 2010 (CONT’D)" & @CRLF & _ "The Group The Company" & @CRLF & _ "Restated Restated" & @CRLF & _ "RM RM RM RM RM" & @CRLF & _ "Current Liabilities" & @CRLF & _ "Amount due to contract customers 24 0 47,202 0 0 0" & @CRLF & _ "Trade payables 25 20,502,454 12,556,468 19,452,763 0 0" & @CRLF & _ "Other payables and accrued expenses 25 16,264,903 12,506,798 18,195,181 310,144 253,253" & @CRLF & _ "Amount owing to subsidiaries 19 0 0 0 16,668,838 18,707,340" & @CRLF & _ "Amount owing to associates 13 0 117,594 300,858 0 0" & @CRLF & _ "Bank overdrafts 26 1,230,283 3,365,362 5,617,839 0 0" & @CRLF & _ "Bank borrowings 26 22,132,228 18,367,015 18,471,490 0 0" & @CRLF & _ "Deferred income 0 0 19,248 0 0" & @CRLF & _ "Hire purchase payables 23 7,249,505 8,223,614 5,906,750 0 0" & @CRLF & _ "Tax liabilities 1,095,025 630,552 1,338,855 0 0" 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