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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^\\w[a-z][^\\d:\\n]+$\\s[a-z][^\\d]+((-[\\d,]+|[\\d,]+)\\s(\\s+)?(-[\\d,]+|[\\d,]+).*)"; final String string = "RM RM\n" + "CASH FLOWS FROM/(FOR) OPERATING ACTIVITIES\n" + "Profit before tax 96,261,457 75,615,413 23,786,496 17,519,528\n" + "Adjustments for:\n" + "Depreciation of property, plant and\n" + "equipment 15,777,521 17,300,505 17,205 17,331\n" + "Depreciation of right-of-use assets 2,040,669 0 94,956 0\n" + "Interest expense 755,525 568,006 9,480 56,109\n" + "Unrealised (gain)/loss on foreign exchange (81,588) (616,303) 20,673 190,487\n" + "Allowance for impairment losses on amount\n" + "owing by subsidiaries 0 0 0 1,242,999\n" + "Allowance for impairment losses on\n" + "receivables 0 932,838 0 0\n" + "Bad debt written off 0 153,130 0 0\n" + "Gain on disposal of an associate 0 (672,207) 0 0\n" + "Property, plant and equipment written off 35 10,678 0 0\n" + "Share of results in an associate 0 (78,115) 0 0\n" + "Interest income (1,150,023) (917,220) (455,564) (549,987)\n" + "Gain on disposal of property, plant\n" + "and equipment (14,417) (164,099) 0 0\n" + "Writeback of allowance for impairment losses\n" + "on amount owing by subsidiaries 0 0 (271,455) 0\n" + "Writeback of allowance for impairment losses\n" + "on trade receivables (2,200) (10,000) 0 0\n" + "Dividend income from subsidiaries 0 0 (28,541 ,623) (23,527,968)\n" + "Operating Profit/(Loss) Before\n" + "Working Capital Changes 113,586,979 92,122,626 (5,339,832) (5,051,501)\n" + "Increase)/Decrease in:\n" + "Inventories (1,274,623) (379,713) 0 0\n" + "Trade receivables 20,924,616 (16,590,199) 0 0\n" + "Other receivables and prepaid expenses (564,806) (1,492,450) (3,691) (27,867)\n" + "Amount owing by an associate 0 1,330,780 0 0\n" + "Decrease)/Increase in:\n" + "Trade payables (1,313,328) (826,277) 0 0\n" + "Other payables and accrued expenses 3,319,226 3,376,361 503,145 1,190,933\n" + "Cash Generated From/(For) Operations 134,678,064 77,541,128 (4,840,378) (3,888,435)\n" + "Taxes paid (19,777,287) (14,218,858) 0 0\n" + "Net Cash From/(For) Operating Activities 114,900,777 63,322,270 (4,840,378) (3,888,435)\n" + "The accompanying NOTEs form an integral part of these Financial Statements.\n" + "Frontken STEAL BERGHE Sais 57\n" + "Statements Of Cash Flows\n" + "For The Financial Year Ended 31 December 2019 (cont’d)\n" + "The Group The Company\n" + "2019 2018 2019 2018\n" + "RM RM\n" + "CASH FLOWS (FOR)/FROM INVESTING ACTIVITIES\n" + "Repayment from subsidiaries 0 0 271,455 1,514,464\n" + "Purchase of property, plant and equipment (7,016,576) (7,492,297) 0 (3,689)\n" + "Addition of right-of-use assets (15,434) 0 0 0\n" + "Dividend received from subsidiaries 0 0 28,038,195 21,039,335\n" + "Additional investment/acquisition of\n" + "subsidiaries (2,636,981) (7,133,082) (2,636,981) (7,133,082)\n" + "Proceeds from disposal of an associate 0 2,496,557 0 0\n" + "Pro (ceeds)/from disposal of property, plant\n" + "and equipment 14,901 1,077,256 0 0\n" + "Net (placement)/withdrawal of fixed\n" + "deposits with licensed banks (3,608,920) 2,992,578 0 1,104,683\n" + "Interest received 1,150,023 917,220 455,564 549,987\n" + "Net Cash (For)/From Investing Activities (12,112,987) (7,141,768) 26,128,233 17,071,698\n" + "CASH FLOWS FOR FINANCING ACTIVITIES\n" + "Decrease)/Increase in amount owing\n" + "to subsidiaries 0 0 (4,851,365) 591,745\n" + "Repayment of term loans (10,677,444) (16,712,117) 0 (2,037,933)\n" + "Interest paid (755,525) (568,006) (9,480) (56,109)\n" + "Dividend paid by the Company (18,863,433) (7,335,779) (18,863,433) (7,335,779)\n" + "Dividend paid by 0 subsidiary to non-\n" + "controlling interests (1,048,152) (2,626,027) 0 0\n" + "Payment of hire purchase payables 0 (544,511) 0 0\n" + "Payment of lease liabilities (2,366,158) 0 (92,640) 0\n" + "Net Cash For Financing Activities (33,710,712) (27,786,440) (23,816,918) (8,838,076)\n" + "NET INCREASE/(DECREASE) IN CASH AND\n" + "CASH EQUIVALENTS 69,077,078 28,394,062 (2,529,063) 4,345,187\n" + "Effect of exchange rate changes 1,651,600 293,086 (59,241) 8,004\n" + "CASH AND CASH EQUIVALENTS\n" + "AT BEGINNING OF YEAR 148,940,067 120,252,919 14,110,208 9,757,017\n" + "CASH AND CASH EQUIVALENTS\n" + "AT END OF YEAR 219,668,745 148,940,067 11,521,904 14,110,208"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html