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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

const regex = /([\,]?)(.*?),(.*?),(.*?),([^,\n]+)/g; // Alternative syntax using RegExp constructor // const regex = new RegExp('([\\,]?)(.*?),(.*?),(.*?),([^,\\n]+)', 'g') const str = `-5,1270516,36,4511997,-5,12376876,36,44785827,-5,12316936,36,44645229,-5,12098128,36,44464959,-5,11927452,36,44249823,-5,11787448,36,44130483,-5,11503048,36,43988193,-5,11298136,36,43932321,-5,11051788,36,43890813,-5,1062994,36,43792524,-5,1073704,36,44205732,-5,1092262,36,4427127,-5,10928704,36,4449573,-5,11439868,36,44664156,-5,11416072,36,4494348,-5,12014428,36,45678996,-5,12379684,36,45426204,-5,1270516,36,4511997 -5,2373088,36,4018572,-5,24624112,36,40067244,-5,2491384,36,39872772,-5,25086388,36,39455001,-5,2521966,36,39240261,-5,2551792,36,39058875,-5,25849336,36,38917395,-5,25736728,36,38870469,-5,25593844,36,3882411,-5,25539412,36,38690235,-5,2515756,36,38599326,-5,24923452,36,38546505,-5,24732616,36,38415195,-5,2461486,36,38364264,-5,2444962,36,38420514,-5,24023056,36,38179152,-5,23217088,36,39022551,-5,2373088,36,4018572`; const subst = `$1$2.$3 $4.$5`; // The substituted value will be contained in the result variable const result = str.replace(regex, subst); console.log('Substitution result: ', result);

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions