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

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 Rust, please visit: https://docs.rs/regex/latest/regex/