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

/
/
gm

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 = "(?:(\\w)(?=(?:(?:[^~]+)~)*(?:\\1=(\\d{96}))))|~[^\\n]+"; final String string = "enter any text you want here and use the substitution in the second part to decode it back to words\n\n" + "~t=483448348344834834444448344444448344444483444444985648348344834483483444444834444448344444444454~h=323483448348344834483483444444834444444444444341985648348344834483483444444834444448344444444454~i=013448348348344444834483483444444834444444444432985648348344834483483444444834444448344444444454~s=956483444834483448348344444483444444834444444687985648348344834483483444444834444448344444444454~a=655648348344444454834834483483444444834444444444985648348344834483483444444834444448344444444454~e=564834448348344834483483444444834444444444445655985648348344834483483444444834444448344444444454~b=676548344834834448344834834444448344444444444468985648348344834483483444444834444448344444444454~c=766548484834483483444444834444443483444444344467985648348344834483483444444834444448344444444454~d=984834483483444444483448348344444483444444446569985648348344834483483444444834444448344444444454~f=985648348344834483483444444834444448344444444454985648348344834483483444444834444448344444444454~g=365483444848344834834444448344444434834444444654985648348344834483483444444834444448344444444454~j=456544848344834834444448344444434834444448344472985648348344834483483444444834444448344444444454~k=365483483484834483483444444834444443444444444692985648348344834483483444444834444448344444444454~l=064834483484834483483444444834444443444444445602985648348344834483483444444834444448344444444454~m=648344448348344444483448348344444483444444456566985648348344834483483444444834444448344444444454~n=483483444448344834834444448344444444483483444444985648348344834483483444444834444448344444444454~o=885554483483444448344834834444448344444444834448985648348344834483483444444834444448344444444454~p=996548344834483483444444834444444834834444444469985648348344834483483444444834444448344444444454~q=876564834834848344834834444448344444434444444446985648348344834483483444444834444448344444444454~r=1164834834834483483444444834444444444445483444661985648348344834483483444444834444448344444444454~u=4933483483484834483483444444834444443444444444351985648348344834483483444444834444448344444444454~v=874834834444448344834834444448344444444483444548985648348344834483483444444834444448344444444454~w=344834483483483448348344444483444444444444444563985648348344834483483444444834444448344444444454~x=954794834448344834834444448344444448348344444449985648348344834483483444444834444448344444444454~y=844834483483483448348344444483444444444444443399985648348344834483483444444834444448344444444454~z=389483444483483444444533985648348344834483483444444834444448344444444454~"; final String subst = "$2"; 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