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

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 = "\\s*(\\d+)\\s+((([0-9a-zA-Z-.]+)\\s*(\\([0-9.]+\\))?((\\s*(([0-9.]+\\s+ms+|[*])\\s?))+))*)$"; final String string = " 1 rbx1-3b-a9.fr.eu (91.121.19.253) 1.648 ms 3.061 ms 3.220 ms\n" + " 2 be11-315.rbx-g2-a9.fr.eu (37.187.231.107) 0.763 ms be11-315.rbx-g1-a9.fr.eu (37.187.231.105) 0.821 ms be11-146.rbx-g2-a9.fr.eu (37.187.231.97) 1.300 ms\n" + " 3 be100-1120.fra-5-a9.de.eu (37.187.232.96) 12.250 ms be100-1105.fra-1-a9.de.eu (37.187.232.88) 12.354 ms be100-1120.fra-5-a9.de.eu (37.187.232.96) 12.293 ms\n" + " 4 r2223.bee.lt (80.81.194.118) 42.643 ms 42.734 ms 42.870 ms\n" + " 5 213.252.224.238 (213.252.224.238) 43.368 ms 43.399 ms 84.15.6.226 (84.15.6.226) 43.676 ms\n" + " 6 84.15.6.226 (84.15.6.226) 43.460 ms 213.226.129.50 (213.226.129.50) 40.203 ms 84.15.6.226 (84.15.6.226) 43.329 ms\n" + " 7 s1v3.e-lietuva.lt (141.136.40.34) 40.225 ms 213.226.129.50 (213.226.129.50) 40.106 ms * 40.082 ms\n\n\n\n\n" + " 1 10.44.17.1 1.867 ms 2.184 ms 2.505 ms\n" + " 2 10.44.23.194 0.519 ms 0.527 ms 0.552 ms\n" + " 3 149.255.125.81 2.775 ms 2.772 ms 2.753 ms\n" + " 4 149.255.121.65 3.248 ms 3.248 ms 3.230 ms\n" + " 5 95.141.160.10 3.726 ms 4.469 ms 4.496 ms\n" + " 6 95.141.175.57 4.514 ms 4.187 ms 4.112 ms\n" + " 7 213.248.85.228 4.188 ms 3.066 ms 2.890 ms\n" + " 8 213.155.132.194 4.066 ms 80.91.248.217 3.944 ms 80.91.247.91 3.791 ms\n" + " 9 62.115.114.183 3.971 ms 62.115.137.195 3.851 ms 62.115.114.185 3.580 ms\n" + "10 213.248.96.38 3.665 ms 3.336 ms 4.168 ms\n" + "11 4.69.159.5 43.000 ms 4.69.159.13 39.696 ms 39.691 ms\n" + "12 4.69.159.1 39.746 ms 4.69.159.13 39.768 ms 4.69.159.1 37.748 ms\n" + "13 213.242.110.210 58.621 ms 58.280 ms 58.177 ms\n" + "14 213.252.224.238 52.065 ms 54.569 ms 54.523 ms\n" + "15 213.226.129.50 55.727 ms 58.060 ms 58.035 ms\n" + "16 141.136.40.34 54.680 ms 54.164 ms 52.145 ms\n\n\n" + " 1 10.44.17.1 15.972 ms 16.312 ms 16.652 ms\n" + " 2 10.44.23.194 0.715 ms 0.729 ms 0.807 ms\n" + " 3 149.255.125.81 1.180 ms 1.194 ms 1.239 ms\n" + " 4 149.255.121.65 3.089 ms 3.106 ms 3.102 ms\n" + " 5 95.141.160.10 2.996 ms 3.013 ms 3.008 ms\n" + " 6 95.141.175.57 7.785 ms 7.121 ms 7.107 ms\n" + " 7 213.248.85.228 4.309 ms 3.949 ms 3.936 ms\n" + " 8 213.155.136.76 2.880 ms 2.824 ms 2.830 ms\n" + " 9 213.155.136.97 8.128 ms 213.155.136.83 8.276 ms 213.155.130.26 8.158 ms\n" + "10 213.155.136.247 9.010 ms 62.115.116.221 9.729 ms 213.155.136.247 8.261 ms\n" + "11 195.12.255.246 9.696 ms 213.248.101.38 9.287 ms 195.12.255.246 9.531 ms\n" + "12 * * *\n" + "13 188.166.33.86 10.182 ms 9.489 ms 9.599 ms"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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