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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
gm

Test String

Code Generator

Generated Code

const regex = /\d{44}/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('\\d{44}', 'gm') const str = ` Found 55 barcodes: 1) I2of5, Confidence: 1,00, Page 1, Rectangle: [231; 2494; 1271; 1] Value: 89620000002429000411110202208291001225388559 2) I2of5, Confidence: 0,50, Page 2, Rectangle: [606; 645; 219; 1] Value: 3505 3) I2of5, Confidence: 1,00, Page 2, Rectangle: [266; 2478; 1270; 1] Value: 89650000002409000411110202207291001225323761 4) I2of5, Confidence: 0,50, Page 3, Rectangle: [2058; 1985; 192; 1] Value: 5862 5) I2of5, Confidence: 0,50, Page 3, Rectangle: [260; 2485; 1270; 1] Value: 89680000002429000411110202208291001225388504 6) I2of5, Confidence: 0,50, Page 4, Rectangle: [1544; 1229; 280; 1] Value: 0316 7) I2of5, Confidence: 0,50, Page 4, Rectangle: [279; 2487; 1271; 1] Value: 89620000002429000411110202208291001225388502 8) I2of5, Confidence: 1,00, Page 5, Rectangle: [258; 2491; 1271; 1] Value: 89610000002429000411110202208291001225388499 9) I2of5, Confidence: 0,50, Page 6, Rectangle: [237; 2601; 1271; 1] Value: 89660000002553300411110202208291001225310933 10) I2of5, Confidence: 0,50, Page 7, Rectangle: [575; 1557; 220; 1] Value: 1555 11) I2of5, Confidence: 0,50, Page 7, Rectangle: [239; 2508; 1270; 1] Value: 89670000002429000411110202208291001225388552 12) I2of5, Confidence: 0,50, Page 8, Rectangle: [254; 2413; 1270; 1] Value: 89650000002429000411110202208291001225388497 13) I2of5, Confidence: 0,50, Page 9, Rectangle: [584; 1563; 226; 1] Value: 1545 14) I2of5, Confidence: 0,50, Page 9, Rectangle: [237; 2515; 1271; 1] Value: 89610000002429000411110202208291001225388480 15) I2of5, Confidence: 0,50, Page 10, Rectangle: [575; 655; 228; 1] Value: 2555 16) I2of5, Confidence: 0,50, Page 10, Rectangle: [578; 1553; 226; 1] Value: 1555 17) I2of5, Confidence: 1,00, Page 10, Rectangle: [236; 2497; 1270; 1] Value: 89620000002429000411110202208291001225388540 18) I2of5, Confidence: 0,50, Page 11, Rectangle: [231; 2475; 1266; 1] Value: 89680000003888000411110202208191001225366638 19) I2of5, Confidence: 0,50, Page 12, Rectangle: [231; 2473; 1266; 1] Value: 89680000003888000411110202208191001225366662 20) I2of5, Confidence: 0,50, Page 13, Rectangle: [1517; 364; 280; 1] Value: 0316 21) I2of5, Confidence: 0,50, Page 13, Rectangle: [619; 614; 319; 1] Value: 797113 22) I2of5, Confidence: 0,50, Page 13, Rectangle: [264; 2539; 1265; 1] Value: 89600000002429000411110202208261001225388255 23) I2of5, Confidence: 1,00, Page 14, Rectangle: [228; 2523; 641; 1] Value: 8968000000281200041111 24) I2of5, Confidence: 1,00, Page 14, Rectangle: [228; 2526; 815; 1] Value: 8968000000281200041111020220 25) I2of5, Confidence: 0,50, Page 14, Rectangle: [228; 2533; 1214; 1] Value: 896800000028120004111102022082610012253881 26) I2of5, Confidence: 0,50, Page 14, Rectangle: [228; 2535; 1263; 1] Value: 89680000002812000411110202208261001225388113 27) I2of5, Confidence: 0,50, Page 15, Rectangle: [275; 2539; 1264; 1] Value: 89660000002429000411110202208261001225388115 28) I2of5, Confidence: 1,00, Page 16, Rectangle: [249; 2454; 1263; 1] Value: 89610000002429000411110202208291001225388512 29) I2of5, Confidence: 0,50, Page 17, Rectangle: [581; 679; 228; 1] Value: 2505 30) I2of5, Confidence: 1,00, Page 17, Rectangle: [581; 1548; 209; 1] Value: 3759 31) I2of5, Confidence: 0,50, Page 17, Rectangle: [240; 2622; 1263; 1] Value: 89600000000971600411110202208291001225388554 32) I2of5, Confidence: 0,50, Page 18, Rectangle: [1502; 1192; 279; 1] Value: 0316 33) I2of5, Confidence: 1,00, Page 18, Rectangle: [243; 2376; 1263; 1] Value: 89610000003037000411110202208291001225388574 34) I2of5, Confidence: 0,50, Page 19, Rectangle: [1484; 1229; 279; 1] Value: 0316 35) I2of5, Confidence: 0,50, Page 19, Rectangle: [224; 2454; 1263; 1] Value: 89690000002429000411110202208291001225388773 36) I2of5, Confidence: 0,50, Page 20, Rectangle: [276; 2536; 1262; 1] Value: 89650000002429000411110202208291001225388812 37) I2of5, Confidence: 0,50, Page 21, Rectangle: [590; 1578; 225; 1] Value: 2505 38) I2of5, Confidence: 0,50, Page 21, Rectangle: [242; 2566; 1263; 1] Value: 89600000002510000411110202208291001225388894 39) I2of5, Confidence: 0,50, Page 22, Rectangle: [576; 1500; 228; 1] Value: 1505 40) I2of5, Confidence: 0,50, Page 22, Rectangle: [234; 2451; 1263; 1] Value: 89620000002429000411110202208291001225388936 41) I2of5, Confidence: 1,00, Page 23, Rectangle: [224; 2457; 1263; 1] Value: 89610000002892000411110202208291001225388743 42) I2of5, Confidence: 0,50, Page 24, Rectangle: [575; 670; 225; 1] Value: 3505 43) I2of5, Confidence: 0,50, Page 24, Rectangle: [573; 1578; 225; 1] Value: 3595 44) I2of5, Confidence: 0,50, Page 24, Rectangle: [230; 2533; 1263; 1] Value: 89630000002579000411110202208291001225388890 45) I2of5, Confidence: 0,50, Page 25, Rectangle: [584; 1583; 223; 1] Value: 2545 46) I2of5, Confidence: 0,50, Page 25, Rectangle: [240; 2536; 1263; 1] Value: 89660000002429000411110202208291001225389825 47) I2of5, Confidence: 0,50, Page 26, Rectangle: [240; 2539; 1265; 1] Value: 89610000002429000411110202208291001225389941 48) I2of5, Confidence: 1,00, Page 27, Rectangle: [1814; 312; 226; 1] Value: 829571 49) I2of5, Confidence: 0,50, Page 27, Rectangle: [231; 2382; 1263; 1] Value: 89640000003037000411110202208291001225388431 50) I2of5, Confidence: 0,50, Page 28, Rectangle: [231; 2533; 1263; 1] Value: 89660000003037000411110202208291001225388307 51) I2of5, Confidence: 0,50, Page 29, Rectangle: [582; 1349; 159; 1] Value: 4416 52) I2of5, Confidence: 0,50, Page 29, Rectangle: [237; 2455; 1265; 1] Value: 89670000003037000411110202208291001225390079 53) I2of5, Confidence: 0,50, Page 30, Rectangle: [1932; 528; 140; 1] Value: 0884 54) I2of5, Confidence: 0,50, Page 30, Rectangle: [269; 552; 136; 1] Value: 8222 55) I2of5, Confidence: 0,50, Page 30, Rectangle: [231; 2527; 1265; 1] Value: 89670000003012000411110202208291001225390108 Decoding took: 1,705 seconds. Preparations: 1,232 seconds. `; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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