Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

/
/
mg

Test String

Substitution

Processing...

Code Generator

Generated Code

re = /^(((\r?\n|\s)*[A-Za-z0-9+\/]){4})*(((\r?\n|\s)*[A-Za-z0-9+\/]){2}(=(\r?\n|\s)*){2}|((\r?\n|\s)*[A-Za-z0-9+\/]){3}(=(\r?\n|\s)*))?$/m str = ' This is a good test to check for base64 encoded strings because it forces the string to begin and end in its own line== Arriba Cachipurriana 00000000: 4e 18 ac 8a c6 a0 a2 87 6d 7a cb 6d a1 c8 5e 72 :N.......mz.m..^r 00000010: 47 e8 ad b6 ac 7b ae 1e 9d ca 1d 79 db 2d ae 29 :G....{.....y.-.) 00000020: e0 b1 b7 9c 6a eb 1e 8a d7 e8 ad c7 ac b6 17 ac :....j........... 00000030: b6 b8 a7 82 da 1b 7a 08 a7 6a 77 5e 9d d8 a7 8a :......z..jw^.... 00000040: db 28 c2 79 62 9d :.(.yb. 00000046. -- CglUaGlzIGlzIGEgZ29vZCB0ZXN0IAp0byBjaGVjayBmb3IgYmFzZTY0IGVuY29kZWQgCnN0cmlu Z3MgYmVjYXVzZSBpdCBmb3JjZXMgCnRoZSBzdHJpbmcgdG8gYmVnaW4gYW5kIGVuZCAKaW4gaXRz IG93biBsaW5lPT0KQXJyaWJhIENhY2hpcHVycmlhbmEKMDAwMDAwMDA6IDRlIDE4IGFjIDhhIGM2 IGEwIGEyIDg3IDZkIDdhIGNiIDZkIGExIGM4IDVlIDcyIDpOLi4uLi4uLm16Lm0uLl5yCjAwMDAw MDEwOiA0NyBlOCBhZCBiNiBhYyA3YiBhZSAxZSA5ZCBjYSAxZCA3OSBkYiAyZCBhZSAyOSA6Ry4u Li57Li4uLi55Li0uKQowMDAwMDAyMDogZTAgYjEgYjcgOWMgNmEgZWIgMWUgOGEgZDcgZTggYWQg YzcgYWMgYjYgMTcgYWMgOi4uLi5qLi4uLi4uLi4uLi4KMDAwMDAwMzA6IGI2IGI4IGE3IDgyIGRh IDFiIDdhIDA4IGE3IDZhIDc3IDVlIDlkIGQ4IGE3IDhhIDouLi4uLi56Li5qd14uLi4uCjAwMDAw MDQwOiBkYiAyOCBjMiA3OSA2MiA5ZCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA6Ligu eWIuCjAwMDAwMDQ2Cg== ' subst = '<<<$0>>>' result = str.gsub(re, subst) # Print the result of the substitution puts 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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html