Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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]
  • 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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

const regex = /\s*(fill|stroke)="(.*?)"/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('\\s*(fill|stroke)="(.*?)"', 'gm') const str = `<svg fill="none" height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g stroke="#2a5ee4" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="m6.66675 8.66673c.2863.38275.65157.69945 1.07103.92862s.88331.36545 1.36007.3996.95525-.03465 1.40315-.2017c.4478-.16706.8545-.42848 1.1924-.76652l2-2c.6072-.62868.9432-1.47069.9356-2.34468-.0076-.87398-.3582-1.71003-.9762-2.32805-.618-.61803-1.4541-.96859-2.328-.97619-.874-.00759-1.71604.32839-2.34472.93558l-1.14667 1.14"/><path d="m9.33322 7.33332c-.2863-.38275-.65157-.69945-1.07103-.92863-.41946-.22917-.88331-.36545-1.36007-.39959-.47676-.03415-.95529.03464-1.40313.2017s-.85451.42847-1.19243.76652l-2 2c-.6072.62867-.94318 1.47068-.93558 2.34468.00759.874.35815 1.71.97618 2.328.61803.6181 1.45407.9686 2.32806.9762s1.71599-.3284 2.34467-.9355l1.14-1.14"/></g></svg>`; const subst = ``; // 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