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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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

"
"
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?m)\b(\d{1,}([ ]\d{3})*)([,.] ?(\d*))?\b`) var str = `== some english sentences == pay 123 usd i want to transfer 100,1234$ how many USD will i get for 47,11 EUR? Please advice how can I add cash 4000eur on this ban account? I would like to buy in your bank 3000 euro. I’ve deposited 2000$ on on the day of opening my account 50€ transferred to my bank account Why did the bank put the 50,000 US dollars transferred to me into my euro account == some slovak sentences == Ahoj prečo mám na účtu -165 eura ? Ako uhradim na česky účet 800 CZK ? Chcem spravit prevod nad limit 30000€ chcem vyplatiť restruktulizovane prečerpanie vo výške 270, 83 € Adam, potrebujem zamenit 18.000 eur na Ceske koruny. Mozem dostat individualny kurz? Chcela by som zamenit české koruny v sume 20 000 na eura Chcem zamenit 10000 forintov na euro mate aj poplatok chcem si na pobočke v Malackách zameniť 7800 CHF na Euro. chcel by som zameniť české koruny na euro aký je kurz aake sú poplatky suma by bola 25000ceskych korún Koľko je 10 000 € keď si zamenim za poľské zlote ? mám 10.000 USD a chcem ich zameniť na euro chce aby som zamenil 31eur na doláre Ak chcem kupovat od banky franky, tak ide zo strany banky o predaj valut, a je tam kurz valuta predaj franky 0,9889 == simple numbers == 100,10 425,90 50.000kc 62,17 eur -0,13€ 10,- eur -100€ 1000000eur 10134,20cz 4.000 40tisíc 45,000 9.93eur == length corner cases: == 12345678901234567890 --> up to 20 digits 1,12345678 --> up to 8 post-comma digits --> value = 1,1235 (rounded)? 1,12345678 --> up to 8 post-comma digits --> value = 1,1234 (truncated)? 123.123.123,123567 --> what about more than 4 decimal places: --> to be confirmed == unusual post-comma leghts: == 10,1 10,123 == what about separators for thousand groups like: == 123.123.123,00 EUR 123 123 123 USD --> this is questionable (not usual in Slovak) == allow dot for comma? == 123.12 --> value = 123,1200 --> yes, as answered in Inez's questions: ‘,‘ and ‘.‘ are expected only as decimal separators in decimal numbers not as separators of hundreds/thousands etc. (not typical in written Slovak) == things that would NOT need disambiguation: == 123.456 --> to map to value 123,4560 and NOT 123456,0000 ! --> dot considered as decimal separator so map to 123,4560 == things that would need disambiguation: == - none - ` var substitution = "[$0 --> ($1),($4)]" fmt.Println(re.ReplaceAllString(str, substitution)) }

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/