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

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

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html