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

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<line1>^(\w|\s+\w)[a-z]\w+[^\d:]*$)\n(\s+)?(?P<line2>(([A-Za-z ,()]+)|(.*)?(\(\w+.*\)))(\s+)?((-[\d,]+|[\d,]+)\s(\s+)?(-[\d,]+|[\d,]+).*))" Local $sString = "Frontken Corporation Berhad -651020-T 55" & @CRLF & _ "ANNUAL REPORT 2016" & @CRLF & _ "statements Of cash Flows " & @CRLF & _ "For The Year Ended 31 December 2016" & @CRLF & _ " The Group The company " & @CRLF & _ " 2016 2015 2016 2015" & @CRLF & _ " Rm Rm Rm Rm" & @CRLF & _ "CASH FLOWS FROM/ (FOR) OPERATING ACTIVITIES " & @CRLF & _ "Profit before tax 33,344,738 15,998,086 6,154,262 178,853" & @CRLF & _ "Adjustments for: " & @CRLF & _ " Depreciation of property, plant " & @CRLF & _ " and equipment 17,193,402 18,132,726 24,047 23,816" & @CRLF & _ " Interest expense 1,146,951 1,494,353 340,916 555,514" & @CRLF & _ " Allowance for impairment loss " & @CRLF & _ " on plant and equipment 51,841 1,713,303 0 0 " & @CRLF & _ " Unrealised (gain)/loss on " & @CRLF & _ " foreign exchange -1,428,927 -2,918,303 -14,377 2,217,362" & @CRLF & _ " Allowance for impairment losses " & @CRLF & _ " on amount owing by a subsidiary 0 0 1,476,080 0 " & @CRLF & _ " Allowance for impairment losses " & @CRLF & _ " on receivables 133,461 294,518 0 0 " & @CRLF & _ " Impairment loss on investment " & @CRLF & _ " in subsidiaries 0 0 0 441,468" & @CRLF & _ " Inventories written down to net " & @CRLF & _ " realisable value 0 52,272 0 0 " & @CRLF & _ " Inventories written off 492,724 146,823 0 0 " & @CRLF & _ " (Gain)/Loss on dissolution of a subsidiary -719,412 0 107,770 0 " & @CRLF & _ " Property, plant and equipment written off 411,330 2,919,978 0 0 " & @CRLF & _ " Share of results in associates 108,525 -25,186 0 0 " & @CRLF & _ " Loss on disposal of investment in " & @CRLF & _ " a subsidiary 0 1,870,011 0 323,468" & @CRLF & _ " Interest income -769,559 -780,339 -593,490 -879,365" & @CRLF & _ " Loss/(Gain) on disposal of property, " & @CRLF & _ " plant and equipment 68,214 -6,669 0 0 " & @CRLF & _ " Writeback of allowance for impairment " & @CRLF & _ " losses on trade receivables -1,196 -717,433 0 0 " & @CRLF & _ " dividend income from subsidiaries 0 0 -10,313,095 -5,084,439 " & @CRLF & _ "Operating Profit/(Loss) Before" & @CRLF & _ " Working Capital Changes 50,032,092 38,174,140 -2,817,887 -2,223,323" & @CRLF & _ "The accompanying Notes form an integral part of these Financial Statements." & @CRLF & _ "56 Frontken Corporation Berhad -651020-T" & @CRLF & _ "ANNUAL REPORT 2016" & @CRLF & _ "statements Of cash Flows " & @CRLF & _ "For The Year Ended 31 December 2016 (cont’d)" & @CRLF & _ " The Group The company " & @CRLF & _ " 2016 2015 2016 2015" & @CRLF & _ " Rm Rm Rm Rm" & @CRLF & _ "Decrease/(Increase) in: " & @CRLF & _ " Inventories 752,679 -968,022 0 0 " & @CRLF & _ " Amount owing by a contract " & @CRLF & _ " customer 0 1,837,000 0 0 " & @CRLF & _ " Trade receivables -5,097,661 27,182,094 0 0 " & @CRLF & _ " Other receivables and " & @CRLF & _ " prepaid expenses 1,172,632 -733,496 -23,556 25,634" & @CRLF & _ " Amount owing by associates -3,771 28,485 0 0 " & @CRLF & _ "Increase/(Decrease) in: " & @CRLF & _ " Trade payables -11,074,834 -8,029,512 0 0 " & @CRLF & _ " Other payables and accrued expenses 15,324,322 -4,748,405 -138,524 -455,447 " & @CRLF & _ "Cash Generated From/" & @CRLF & _ " (For) Operations 51,105,459 52,742,284 -2,979,967 -2,653,136 " & @CRLF & _ "Taxes paid -6,681,818 -8,242,591 0 0 " & @CRLF & _ "Net Cash From/(For) " & @CRLF & _ " Operating Activities 44,423,641 44,499,693 -2,979,967 -2,653,136 " & @CRLF & _ "CASH FLOWS (FOR)/FROM INVESTING ACTIVITIES " & @CRLF & _ "Repayment from subsidiaries 0 0 8,435,398 5,252,690" & @CRLF & _ "Purchase of property, plant and " & @CRLF & _ " equipment -27,730,908 -7,196,780 -2,929 -2,849" & @CRLF & _ "dividend received from subsidiaries 0 0 4,268,995 4,634,439" & @CRLF & _ "Additional investment/acquisition " & @CRLF & _ " of subsidiaries (Note 11) -7,399,144 -6,862,024 -7,399,142 -5,103,100" & @CRLF & _ "Net cash outflow on disposal of a " & @CRLF & _ " subsidiary (Note 11) 0 -785,413 0 0 " & @CRLF & _ "Proceeds from disposal of property, plant" & @CRLF & _ " and equipment 188,769 77,955 0 -" & @CRLF & _ "proceeds from disposal of a subsidiary 0 0 0 85,304" & @CRLF & _ "Short-term investment -2,243,001 0 0 0 " & @CRLF & _ "Net withdrawal/(placement) of fixed" & @CRLF & _ " deposits with licensed banks 1,377,357 6,600,196 -32,254 6,967,605" & @CRLF & _ "Interest received 769,559 780,339 593,490 879,365 " & @CRLF & _ "Net Cash (For)/From " & @CRLF & _ " Investing Activities -35,037,368 -7,385,727 5,863,558 12,713,454" & @CRLF & _ "The accompanying Notes form an integral part of these Financial Statements." & @CRLF & _ "Frontken Corporation Berhad -651020-T 57" & @CRLF & _ "ANNUAL REPORT 2016" & @CRLF & _ "statements Of cash Flows " & @CRLF & _ "For The Year Ended 31 December 2016 (cont’d)" & @CRLF & _ " The Group The company " & @CRLF & _ " note 2016 2015 2016 2015" & @CRLF & _ " Rm Rm Rm Rm" & @CRLF & _ "CASH FLOWS (FOR)/FROM FINANCING ACTIVITIES " & @CRLF & _ "decrease in amount owing to" & @CRLF & _ " subsidiaries 0 0 -1,680,840 -2,275,689" & @CRLF & _ "Treasury shares acquired -64,491 -33,751 -64,491 -33,751" & @CRLF & _ "proceeds from issuance of shares 0 7,564,855 0 7,564,855" & @CRLF & _ "repayment of term loans -30,567,224 -878,769 -1,936,843 -1,810,825" & @CRLF & _ "Interest paid -1,146,951 -1,494,353 -340,916 -555,514" & @CRLF & _ "dividend paid by a subsidiary to non-" & @CRLF & _ " controlling interests -2,151,371 -1,806,882 0 0 " & @CRLF & _ "Drawdown of term loans 16,146,540 4,401,620 0 -" & @CRLF & _ "payment of hire purchase payables -689,599 -1,506,234 0 0 " & @CRLF & _ "net cash (For)/From" & @CRLF & _ " Financing Activities -18,473,096 6,246,486 -4,023,090 2,889,076 " & @CRLF & _ "net (Decrease)/increase " & @CRLF & _ " in cash And cash " & @CRLF & _ " Equivalents -9,086,823 43,360,452 -1,139,499 12,949,394 " & @CRLF & _ "Effect of exchange rate changes 2,037,383 9,181,739 63,094 116,833 " & @CRLF & _ "cAsH AnD cAsH EQUiVALEnTs " & @CRLF & _ " AT BEGinninG OF YEAR 105,117,339 52,575,148 16,460,512 3,394,285 " & @CRLF & _ "cAsH AnD cAsH EQUiVALEnTs " & @CRLF & _ "*" & @CRLF & _ " AT EnD OF YEAR 98,067,899 105,117,339 15,384,107 16,460,512" & @CRLF & _ "Note : During the financial year, the Group and the Company acquired property, plant and equipment at an aggregate cost " & @CRLF & _ "of RM27,900,908 and RM2,929 -2015 : RM7,196,780 and RM2,849, respectively, of which RM170,000 and NIL " & @CRLF & _ "-2015 : NIL and NIL, respectively, was acquired under hire-purchase arrangements. " & @CRLF & _ "*" & @CRLF & _ " The Group The company " & @CRLF & _ " 2016 2015 2016 2015" & @CRLF & _ " Rm Rm Rm Rm" & @CRLF & _ "cAsH AnD cAsH EQUiVALEnTs " & @CRLF & _ "Cash and bank balances 88,745,512 94,486,988 9,993,581 14,460,511" & @CRLF & _ "Fixed deposits with licensed banks 5,872,035 15,310,588 1,072,697 3,040,444" & @CRLF & _ "Short-term investments - unit trust 6,753,232 0 5,390,526 0 " & @CRLF & _ " 101,370,779 109,797,576 16,456,804 17,500,955" & @CRLF & _ "Less: Fixed deposits pledged with banks -3,205,263 -4,680,237 -1,072,697 -1,040,443" & @CRLF & _ "Less: Fixed deposits with maturity " & @CRLF & _ " period more than 3months -97,617 0 0 0 " & @CRLF & _ "Cash and cash equivalents 98,067,899 105,117,339 15,384,107 16,460,512" & @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