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)(^[A-Z][a-z][^\d:]*$)\n(\s+)?((([A-Za-z ,]+)|(.*)?(\(\w+.*\)))(\s+)?((-[\d,]+|[\d,]+)\s(\s+)?(-[\d,]+|[\d,]+)(.*)?))" Local $sString = "56 Frontken Corporation Berhad -651020-T " & @CRLF & _ "ANNUAL REPORT 2018 " & @CRLF & _ "Statements Of Cash Flows " & @CRLF & _ "For The Financial Year Ended 31 December 2018 " & @CRLF & _ "The Group The Company " & @CRLF & _ "2018 2017 2018 2017 " & @CRLF & _ "RM RM RM RM " & @CRLF & _ "CASH FLOWS FROM/(FOR) " & @CRLF & _ "OPERATING ACTIVITIES " & @CRLF & _ "Profit before tax 75,615,413 46,147,364 17,519,528 13,008,793 " & @CRLF & _ "Adjustments for: " & @CRLF & _ "Depreciation of property, plant and " & @CRLF & _ " 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 " & @CRLF & _ "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 " & @CRLF & _ "amount owing by a subsidiary 0 0 1,242,999 270,000 " & @CRLF & _ "Allowance for impairment losses on " & @CRLF & _ " 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 " & @CRLF & _ "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 " & @CRLF & _ "and equipment -164,099 -11,181 0 0 " & @CRLF & _ "Writeback of allowance for impairment " & @CRLF & _ "losses on trade receivables Dividend -10,000 -60,137 0 0 " & @CRLF & _ "income from subsidiaries 0 0 -23,527,968 -17,028,204 " & @CRLF & _ "Operating Profit/(Loss) Before " & @CRLF & _ "Working Capital Changes 92,122,626 70,063,654 -5,051,501 -3,952,223 " & @CRLF & _ "(Increase)/Decrease in: " & @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 & _ "(Decrease)/Increase in: " & @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 & _ "Net Cash From/(For) Operating Activities 63,322,270 69,028,775 -3,888,435 -2,981,873 " & @CRLF & _ "The accompanying Notes form an integral part of these Financial Statements. " & @CRLF & _ " " & @CRLF & _ "Frontken Corporation Berhad -651020-T 57 " & @CRLF & _ "ANNUAL REPORT 2018 " & @CRLF & _ "Statements Of Cash Flows " & @CRLF & _ "For The Financial Year Ended 31 December 2018 (cont’d) " & @CRLF & _ "The Group The Company " & @CRLF & _ "2018 2017 2018 2017 " & @CRLF & _ "RM RM RM RM " & @CRLF & _ "CASH FLOWS (FOR)/FROM INVESTING " & @CRLF & _ "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 " & @CRLF & _ "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 " & @CRLF & _ "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 " & @CRLF & _ "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 & _ "Net Cash (For)/From Investing Activities -7,141,768 -32,078,095 17,071,698 11,009,150 " & @CRLF & _ "CASH FLOWS FOR FINANCING ACTIVITIES " & @CRLF & _ "Decrease in amount owing to subsidiaries " & @CRLF & _ "(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- " & @CRLF & _ "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 " & @CRLF & _ "(Note 29(a)) -544,511 -251,063 0 0 " & @CRLF & _ "Net Cash For Financing Activities -27,786,440 -8,388,840 -8,838,076 -13,279,670 " & @CRLF & _ "NET INCREASE/(DECREASE) IN " & @CRLF & _ "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 " & @CRLF & _ "BEGINNING OF YEAR 120,252,919 98,067,899 9,757,017 15,384,107 " & @CRLF & _ "CASH AND CASH EQUIVALENTS AT " & @CRLF & _ "END OF YEAR (Note 29(b)) 148,940,067 120,252,919 14,110,208 9,757,017 " & @CRLF & _ "Note : During the financial year, the Group and the Company acquired property, plant and equipment at an aggregate cost of " & @CRLF & _ "RM9,892,297 and RM3,689 -2017: RM20,152,154 and RM830, respectively, of which RM2,400,000 and NIL -2017: NIL and NIL, " & @CRLF & _ "respectively, was acquired under hire-purchase arrangements. " & @CRLF & _ "The accompanying Notes form an integral part of these Financial Statements. " 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