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

/
/
gm

Test String

Code Generator

Generated Code

const regex = /android\.com\/(intl\/[a-zA-Z]{2}\_[a-zA-Z]{2}\/)?$/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('android\\.com\\\/(intl\\\/[a-zA-Z]{2}\\_[a-zA-Z]{2}\\\/)?$', 'gm') const str = `android.com/intl/en_us/ android.com/intl/en_in/auto/ android.com/intl/en_us/auto/ android.com/intl/en_us/enterprise android.com/enterprise/ android.com/work/84 android.com/enterprise/management/zero-touch/ android.com/security-center/ android.com//com.google.android.googlequicksearchbox android.com/certified/partners/ android.com/ android.com/phones/ android.com/results/ android.com/versions/oreo-8-0/ android.com/filetransfer/ android.com/auto/ android.com/enterprise/ android.com/play-protect/ android.com/one/ android.com/intl/en_us/auto/ developer.android.com/work/index.html android.com/everyone/ android.com/intl/en_in/auto/ android.com/intl/en_us/9 android.com/history/1 android.com/tv/ android.com/tablets/ android.com/enterprise/ developer.android.com/work/overview.html android.com/enterprise/device-catalog/ android.com/intl/en_uk/auto/ android.com/switch/ android.com/enterprise/management/ android.com/gms/ android.com/intl/en_us/pay/ android.com/intl/en_us/one/ android.com/work/ android.com/intl/en_in/phones/ android.com/intl/en_uk/phones/ android.com/wear/ android.com/everyone/enabling-opportunity/ android.com/intl/en_us/phones/ android.com/play/ android.com/intl/en_au/phones/ android.com/intl/en_in/tv/ android.com/intl/en_us/tablets/ android.com/enterprise/ android.com/enterprise/management/ androidbusinesspartners.withgoogle.com/android/partners/search android.com/gms/contact/ android.com/intl/en_in/wear/ android.com/intl/fr_fr/work/ android.com/pay/ android.com/security-center/ android.com/intl/en_ca/auto/ android.com/intl/en_in/wear/lg-watch-urbane-2nd-ed/ android.com/intl/en_uk/ android.com/intl/en_us/tv/ android.com/phones/tips/ android.com/enterprise/ android.com/enterprise/device-catalog/ android.com/enterprise/devices/ android.com/intl/ALL_en/work/ android.com/intl/en_in/ android.com/intl/en_in/results/ android.com/intl/en_in/switch/ android.com/intl/en_in/tv/sony-bravia/ android.com/intl/en_uk/pay/terms/ android.com/intl/en_uk/results/ android.com/intl/en_us/wear/ android.com/intl/it_it/work/ android.com/security-center/monthly-security-updates/ android.com/versions/nougat-7-0/ android.com/enterprise/devices/ android.com/enterprise/devices/ android.com/ android.com/enterprise/management/zero-touch/ androidbusinesspartners.withgoogle.com/android/partners androidbusinesspartners.withgoogle.com/workpartners/accessdenied android.com/intl/de_at/ android.com/intl/en_au/ android.com/intl/en_au/play-protect/ android.com/intl/en_au/work/ android.com/intl/en_ca/phones/ android.com/intl/en_in/phones/samsung-galaxy-s7-edge/ android.com/intl/en_uk/pay/ android.com/intl/en_uk/phones/pixel/ android.com/intl/en_us/pay/participating-banks/ android.com/intl/en_us/switch/ android.com/phones/samsung-galaxy-s7-edge/ android.com/filetransfer/ android.com/intl/en_us/ android.com/intl/de_de/security-center/ android.com/intl/en_au/auto/ android.com/intl/en_in/enterprie/ android.com/intl/en_uk/switch/ android.com/intl/en_uk/tv/sharp-aquos/ android.com/intl/en_us/everyone/ android.com/intl/es_es/security-center/ android.com/intl/it_it/tv/xiaomi-mi-box/ android.com/intl/ja_jp/work/ android.com/intl/pl_pl/security-center/ developer.android.com/work/guide.html android.com/intl/en_uk/enterprise/devices/ android.com/intl/en_in/enterprise/device-collection/ android.com/auto/ android.com/certified/partners/ android.com/enterprise/security/ android.com/intl/en_in/enterprise/devices/ android.com/intl/en_us/auto/ android.com/phones/ android.com/results/ android.com/versions/oreo-8-0/ android.com//com.linkedin.android android.com/auto/audi/ android.com/auto/ford/ android.com/everyone/research/ android.com/intl/en_au/auto/genesis/ android.com/intl/en_au/pay/ android.com/intl/en_au/results/ android.com/intl/en_au/security-center/ android.com/intl/en_au/tv/ android.com/intl/en_ca/ android.com/intl/en_ca/results/ android.com/intl/en_ca/security-center/ android.com/intl/en_ca/tv/nvidia-shield/ android.com/intl/en_ca/tv/sharp-aquos/ android.com/intl/en_hk/certified/partners/ android.com/intl/en_hk/pay/ android.com/intl/en_in/phones/htc-10/ android.com/intl/en_in/security-center/ android.com/intl/en_nz/phones/ android.com/intl/en_uk/auto/audi/ android.com/intl/en_uk/enterprise/ android.com/intl/en_uk/phones/samsung-galaxy-s7-edge/ android.com/intl/en_uk/tablets/ android.com/intl/en_uk/tv/sony-bravia/ android.com/intl/en_us/play/ android.com/intl/en_us/security-center/ android.com/intl/es-419_mx/security-center/ android.com/intl/es_es/tv/xiaomi-mi-box/ android.com/intl/pl_pl/work/ android.com/intl/ru_ru/security-center/ android.com/intl/ru_ru/work/ android.com/phones/moto-x/ android.com/security-center/publications/ android.com/security-center/whats-new/`; // 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