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

/
/
mgi

Test String

Code Generator

Generated Code

const regex = /(^[-rwx]{10}\s*[\w\d]*\s*[^\s]*\s*[^\s]*\s*(?<size>\d*)\s*.{20}\s*(?<name>[^\n]*)$)*/mgi; // Alternative syntax using RegExp constructor // const regex = new RegExp('(^[-rwx]{10}\\s*[\\w\\d]*\\s*[^\\s]*\\s*[^\\s]*\\s*(?<size>\\d*)\\s*.{20}\\s*(?<name>[^\\n]*)$)*', 'mgi') const str = `Searching for host... Connecting to host... Authenticating... Using username "cambrionix-bamboo". Authenticating with pre-entered password. Authenticated. Starting the session... Session started. Active session: [1] cambrionix-bamboo@cambrionix.sftp.wpengine.com transfer binary batch continue /Downloads/API -rw-rw-r-- 0 cambrionix-bamboo www-data 19637888 Mar 29 19:32:58 2022 Cambrionix API Setup 3.2.8-beta+17.exe -rw-rw-r-- 0 cambrionix-bamboo www-data 12898304 Dec 13 15:09:16 2021 Cambrionix API Setup 3.0.2+7.exe -rw-rw-r-- 0 33 www-data 12910208 Jan 27 8:32:26 2022 Cambrionix API Setup 3.1.5+8.exe -rw-rw-r-- 0 33 www-data 12523791 Sep 22 14:20:26 2021 Cambrionix API Setup 2.9.287.exe -rw-rw-r-- 0 33 www-data 12875440 Sep 22 14:20:20 2021 Cambrionix API Setup 2.19.1+2.exe -rw-rw-r-- 0 33 www-data 19423248 Sep 22 14:20:28 2021 Cambrionix API Setup 2.21.9-development+18.exe -rw-rw-r-- 0 cambrionix-bamboo www-data 19730000 Apr 5 16:51:12 2022 Cambrionix API Setup 3.3.0-alpha+216.exe -rw-rw-r-- 0 33 www-data 12868384 Sep 23 14:02:57 2021 Cambrionix API Setup 2.21.15+4.exe -rw-rw-r-- 0 cambrionix-bamboo www-data 19661568 Apr 8 11:35:32 2022 Cambrionix API Setup 3.2.8+10.exe -rw-rw-r-- 0 33 www-data 12873992 Sep 22 14:20:23 2021 Cambrionix API Setup 2.19.1+3.exe -rw-rw-r-- 0 33 www-data 13096592 Sep 22 14:20:24 2021 Cambrionix API Setup 2.16.5+5.exe -rw-rw-r-- 0 33 www-data 12549552 Sep 22 14:20:24 2021 Cambrionix API Setup 2.14.306.exe -rw-rw-r-- 0 33 www-data 7448326 Sep 22 14:20:17 2021 Cambrionix API Setup 2.19.1+2.pkg -rw-rw-r-- 0 33 www-data 4476429 Sep 22 14:20:14 2021 Cambrionix API Setup 2.16.5+5.pkg -rw-rw-r-- 0 33 www-data 4356365 Sep 22 14:20:11 2021 Cambrionix API Setup 2.9.287.pkg -rw-rw-r-- 0 cambrionix-bamboo www-data 7446428 Dec 13 15:09:16 2021 Cambrionix API Setup 3.0.2+7.pkg -rw-rw-r-- 0 cambrionix-bamboo www-data 10661040 Apr 8 11:35:32 2022 Cambrionix API Setup 3.2.8+10.pkg -rw-rw-r-- 0 33 www-data 7448398 Sep 22 14:20:18 2021 Cambrionix API Setup 2.19.1+3.pkg -rw-rw-r-- 0 33 www-data 4281285 Sep 22 14:20:11 2021 Cambrionix API Setup 2.14.306.pkg -rw-rw-r-- 0 cambrionix-bamboo www-data 10688455 Apr 5 16:51:12 2022 Cambrionix API Setup 3.3.0-alpha+216.pkg -rw-rw-r-- 0 33 www-data 10798506 Sep 22 14:20:23 2021 Cambrionix API Setup 2.21.9-development+18.pkg -rw-rw-r-- 0 33 www-data 7450806 Jan 27 8:32:26 2022 Cambrionix API Setup 3.1.5+8.pkg -rw-rw-r-- 0 cambrionix-bamboo www-data 10659854 Mar 29 19:32:58 2022 Cambrionix API Setup 3.2.8-beta+17.pkg -rw-rw-r-- 0 33 www-data 7430270 Sep 23 14:02:57 2021 Cambrionix API Setup 2.21.15+4.pkg -rw-rw-r-- 0 cambrionix-bamboo www-data 3681588 Mar 29 19:32:58 2022 cambrionix-api-setup-3.2.8-beta+17-amd64.deb -rw-rw-r-- 0 cambrionix-bamboo www-data 2164504 Dec 13 15:09:17 2021 cambrionix-api-setup-3.0.2+7-amd64.deb -rw-rw-r-- 0 33 www-data 7753932 Sep 22 14:20:24 2021 cambrionix-api-setup-2.16.5+5-armhf.deb -rw-rw-r-- 0 cambrionix-bamboo www-data 3681436 Apr 8 11:35:32 2022 cambrionix-api-setup-3.2.8+10-amd64.deb -rw-rw-r-- 0 33 www-data 7832428 Sep 22 14:20:15 2021 cambrionix-api-setup-2.19.1+3-armhf.deb -rw-rw-r-- 0 cambrionix-bamboo www-data 9821820 Mar 29 19:32:59 2022 cambrionix-api-setup-3.2.8-beta+17-armhf.deb -rw-rw-r-- 0 33 www-data 2537440 Sep 22 14:20:12 2021 cambrionix-api-setup2.14.306-amd64.deb -rw-rw-r-- 0 33 www-data 2176156 Jan 27 8:32:26 2022 cambrionix-api-setup-3.1.5+8-amd64.deb -rw-rw-r-- 0 33 www-data 7833460 Sep 22 14:20:19 2021 cambrionix-api-setup-2.19.1+2-armhf.deb -rw-rw-r-- 0 33 www-data 2182292 Sep 23 14:02:57 2021 cambrionix-api-setup-2.21.15+4-amd64.deb -rw-rw-r-- 0 33 www-data 7822776 Sep 23 14:02:57 2021 cambrionix-api-setup-2.21.15+4-armhf.deb -rw-rw-r-- 0 33 www-data 7825468 Jan 27 8:32:26 2022 cambrionix-api-setup-3.1.5+8-armhf.deb -rw-rw-r-- 0 33 www-data 9935500 Sep 22 14:20:24 2021 cambrionix-api-setup-2.21.9-development+18-armhf.deb -rw-rw-r-- 0 cambrionix-bamboo www-data 3165116 Apr 5 16:51:12 2022 cambrionix-api-setup-3.3.0-alpha+216-amd64.deb -rw-rw-r-- 0 cambrionix-bamboo www-data 9818924 Apr 8 11:35:33 2022 cambrionix-api-setup-3.2.8+10-armhf.deb -rw-rw-r-- 0 cambrionix-bamboo www-data 7819420 Dec 13 15:09:17 2021 cambrionix-api-setup-3.0.2+7-armhf.deb -rw-rw-r-- 0 33 www-data 3775348 Sep 22 14:20:12 2021 cambrionix-api-setup-2.21.9-development+18-amd64.deb -rw-rw-r-- 0 33 www-data 2167552 Sep 22 14:20:13 2021 cambrionix-api-setup-2.19.1+3-amd64.deb -rw-rw-r-- 0 33 www-data 2687380 Sep 22 14:20:13 2021 cambrionix-api-setup-2.16.5+5-amd64.deb -rw-rw-r-- 0 cambrionix-bamboo www-data 9473480 Apr 5 16:51:12 2022 cambrionix-api-setup-3.3.0-alpha+216-armhf.deb -rw-rw-r-- 0 33 www-data 3278436 Sep 22 14:21:09 2021 cambrionix-api-setup2.14.306-armhf.deb -rw-rw-r-- 0 33 www-data 2167232 Sep 22 14:20:11 2021 cambrionix-api-setup-2.19.1+2-amd64.deb`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; 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