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"
"
gmi

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 = "(?mi)(cash\sflows.*activities$|net.*cash.*and cash equivalents?)" Local $sString = "CASH FLOWS FROM/(FOR) OPERATING ACTIVITIES" & @CRLF & _ "Profit before tax 75,615,413 46,147,364 17,519,528 13,008,793" & @CRLF & _ "Depreciation of property, plant and equipment 17,300,505 18,471,479 17,331 21,667" & @CRLF & _ "Interest expense 568,006 931,264 56,109 194,461" & @CRLF & _ "Allowance for impairment loss on property, plant and equipment 0 49,749 0 0" & @CRLF & _ "Unrealised (gain)/loss on foreign exchange -616,303 4,613,657 190,487 95,813" & @CRLF & _ "Allowance for impairment losses on amount owing by a subsidiary 0 0 1,242,999 270,000" & @CRLF & _ "Allowance for impairment losses on receivables 932,838 71,151 0 0" & @CRLF & _ "Bad debt written off 153,130 0 0 0" & @CRLF & _ "Inventories written off 0 137,087 0 0" & @CRLF & _ "Gain on disposal of an associate -672,207 0 0 0" & @CRLF & _ "Property, plant and equipment written off 10,678 506,875 0 0" & @CRLF & _ "Share of results in an associate -78,115 51,126 0 0" & @CRLF & _ "Interest income -917,220 -844,780 -549,987 -514,753" & @CRLF & _ "Gain on disposal of property, plant and equipment -164,099 -11,181 0 0" & @CRLF & _ "Writeback of allowance for impairment losses on trade receivables Dividend -10,000 -60,137 0 0" & @CRLF & _ "income from subsidiaries 0 0 -23,527,968 -17,028,204" & @CRLF & _ "Inventories -379,713 -2,955,410 0 0" & @CRLF & _ "Trade receivables -16,590,199 2,180,666 0 0" & @CRLF & _ "Other receivables and prepaid expenses -1,492,450 -424,370 -27,867 13,997" & @CRLF & _ "Amount owing by an associate 1,330,780 1,698 0 0" & @CRLF & _ "Trade payables -826,277 -1,354,959 0 0" & @CRLF & _ "Other payables and accrued expenses 3,376,361 9,419,139 1,190,933 956,353" & @CRLF & _ "Cash Generated From/(For) Operations 77,541,128 76,930,418 -3,888,435 -2,981,873" & @CRLF & _ "Taxes paid -14,218,858 -7,901,643 0 0" & @CRLF & _ "CASH FLOWS (FOR)/FROM INVESTING ACTIVITIES" & @CRLF & _ "Repayment from subsidiaries 0 0 1,514,464 9,000,836" & @CRLF & _ "Purchase of property, plant and equipment -7,492,297 -20,152,154 -3,689 -830" & @CRLF & _ "Dividend received from subsidiaries 0 0 21,039,335 14,800,304" & @CRLF & _ "Additional investment/acquisition of subsidiaries (Note 11) -7,133,082 -13,273,927 -7,133,082 -13,273,927" & @CRLF & _ "Proceeds from disposal of an associate 2,496,557 0 0 0" & @CRLF & _ "Proceeds from disposal of property, plant and equipment 1,077,256 138,530 0 0" & @CRLF & _ "Withdrawal of short-term investments 0 2,197,876 0 0" & @CRLF & _ "Net withdrawal/(placement) of fixed deposits with licensed banks 2,992,578 -1,833,200 1,104,683 -31,986" & @CRLF & _ "Interest received 917,220 844,780 549,987 514,753" & @CRLF & _ "CASH FLOWS FOR FINANCING ACTIVITIES" & @CRLF & _ "Decrease in amount owing to subsidiaries (Note 29(a)) 0 0 591,745 -5,754,789" & @CRLF & _ "Repayment of term loans (Note 29(a)) -16,712,117 -7,883,738 -2,037,933 -2,090,577" & @CRLF & _ "Interest paid -568,006 -931,264 -56,109 -194,461" & @CRLF & _ "Dividend paid by the Company (Note 26) -7,335,779 -5,239,843 -7,335,779 -5,239,843" & @CRLF & _ "Dividend paid by a subsidiary to non- controlling interests -2,626,027 -1,984,852 0 0" & @CRLF & _ "Drawdown of term loans (Note 29(a)) 0 7,901,920 0 0" & @CRLF & _ "Payment of hire purchase payables (Note 29(a)) -544,511 -251,063 0 0" & @CRLF & _ "NET INCREASE/(DECREASE) IN CASH AND CASH EQUIVALENTS 28,394,062 28,561,840 4,345,187 -5,252,393" & @CRLF & _ "Effect of exchange rate changes 293,086 -6,376,820 8,004 -374,697" & @CRLF & _ "CASH AND CASH EQUIVALENTS AT BEGINNING OF YEAR 120,252,919 98,067,899 9,757,017 15,384,107" & @CRLF & _ "CASH AND CASH EQUIVALENTS AT END OF YEAR (Note 29(b)) 148,940,067 120,252,919 14,110,208 9,757,017" 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