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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "^(((\\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)*))?$"; final String string = "\n" + " This is a good test \n" + "to check for base64 encoded \n" + "strings because it forces \n" + "the string to begin and end \n" + "in its own line==\n" + "Arriba Cachipurriana\n" + "00000000: 4e 18 ac 8a c6 a0 a2 87 6d 7a cb 6d a1 c8 5e 72 :N.......mz.m..^r\n" + "00000010: 47 e8 ad b6 ac 7b ae 1e 9d ca 1d 79 db 2d ae 29 :G....{.....y.-.)\n" + "00000020: e0 b1 b7 9c 6a eb 1e 8a d7 e8 ad c7 ac b6 17 ac :....j...........\n" + "00000030: b6 b8 a7 82 da 1b 7a 08 a7 6a 77 5e 9d d8 a7 8a :......z..jw^....\n" + "00000040: db 28 c2 79 62 9d :.(.yb.\n" + "00000046.\n" + "--\n" + "CglUaGlzIGlzIGEgZ29vZCB0ZXN0IAp0byBjaGVjayBmb3IgYmFzZTY0IGVuY29kZWQgCnN0cmlu\n" + "Z3MgYmVjYXVzZSBpdCBmb3JjZXMgCnRoZSBzdHJpbmcgdG8gYmVnaW4gYW5kIGVuZCAKaW4gaXRz\n" + "IG93biBsaW5lPT0KQXJyaWJhIENhY2hpcHVycmlhbmEKMDAwMDAwMDA6IDRlIDE4IGFjIDhhIGM2\n" + "IGEwIGEyIDg3IDZkIDdhIGNiIDZkIGExIGM4IDVlIDcyIDpOLi4uLi4uLm16Lm0uLl5yCjAwMDAw\n" + "MDEwOiA0NyBlOCBhZCBiNiBhYyA3YiBhZSAxZSA5ZCBjYSAxZCA3OSBkYiAyZCBhZSAyOSA6Ry4u\n" + "Li57Li4uLi55Li0uKQowMDAwMDAyMDogZTAgYjEgYjcgOWMgNmEgZWIgMWUgOGEgZDcgZTggYWQg\n" + "YzcgYWMgYjYgMTcgYWMgOi4uLi5qLi4uLi4uLi4uLi4KMDAwMDAwMzA6IGI2IGI4IGE3IDgyIGRh\n" + "IDFiIDdhIDA4IGE3IDZhIDc3IDVlIDlkIGQ4IGE3IDhhIDouLi4uLi56Li5qd14uLi4uCjAwMDAw\n" + "MDQwOiBkYiAyOCBjMiA3OSA2MiA5ZCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA6Ligu\n" + "eWIuCjAwMDAwMDQ2Cg==\n"; final String subst = "<<<$0>>>"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceAll(subst); System.out.println("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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html