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

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?mi)Other\spayables?_lt`) var str = `FRONTKEN CORPORATION BERHAD (Co. No. 651020-T) (Incorporated in Malaysia) CONDENSED CONSOLIDATED STATEMENT OF PROFIT OR LOSS AND OTHER COMPREHENSIVE INCOME FOR THE FOURTH QUARTER ENDED 31 DECEMBER 2019 (The figures have not been audited) Individual Quarter Cumulative Quarter Preceding Year Preceding Year Current Year Corresponding Current Year Corresponding Quarter Quarter To-date Period 31 Dec 2019 31 Dec 2018 31 Dec 2019 31 Dec 2018 RM '000 RM '000 RM '000 RM '000 Revenue 8 8,888 88,665 339,911 327,218 Operating expenses (61,106) ( 61,255) ( 228,967) ( 239,240) Profit before depreciation and finance costs 2 7,782 2 7,410 110,944 8 7,978 Depreciation (3,760) (4,268) ( 17,818) (17,301) Finance costs (140) (92) (756) (568) Other operating income 608 1 ,375 3 ,891 5,428 Share of results of associated companies - - - 78 Profit before tax 2 4,490 2 4,425 9 6,261 7 5,615 Taxation (4,905) (4,415) ( 22,033) (18,613) Profit after tax 1 9,585 2 0,010 7 4,228 5 7,002 Profit after tax attributable to : Owners of the Company 1 8,199 1 8,683 6 9,170 5 2,257 Non-controlling interests 1 ,386 1 ,327 5 ,058 4 ,745 Profit for the period 1 9,585 2 0,010 7 4,228 5 7,002 Profit for the period 1 9,585 2 0,010 7 4,228 5 7,002 Other comprehensive expenses: Actuarial gains 4 3 98 4 3 98 Foreign currency translation 2 ,253 7 2 2 ,262 ( 1,571) Total comprehensive income for the period 2 1,842 2 0,480 7 6,494 5 5,829 Total comprehensive income attributable to: Owners of the Company 2 0,277 1 9,172 7 1,291 5 1,317 Non-controlling interests 1 ,565 1 ,308 5 ,203 4 ,512 Total comprehensive income for the period 2 1,842 2 0,480 7 6,494 5 5,829 Earnings per share attributable to equity holders of the company : Basic (sen) 1.74 1.78 6.60 4.99 The condensed consolidated income statement is to be read in conjunction with the accompanying notes to the interim financial report. The comparative figures are based on audited financial statements of the Company for the financial year ended 31 December 2018.` for i, match := range re.FindAllString(str, -1) { fmt.Println(match, "found at index", 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 Golang, please visit: https://golang.org/pkg/regexp/