Regular Expressions 101

Save & Share

  • Regex Version: ver. 3
  • 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
No Match

r"
"
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 = "(?:(?:https?|ftp):\\/\\/)?(?:\\S+(?::\\S*)?@)?(?:((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])|(?:(?:[a-z\\u00a1-\\uffff0-9]+-)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?"; final String string = "https://face.com\n" + "http://face.com\n" + "https://www.face.com/\n" + "face.com\n" + "www.face.com\n" + "w3.face.com\n" + "0.0.0.0\n" + "ac31.23.53.122asd\n" + "92.168.202.9712121212121\n\n" + "1292.168.202.97\n" + "192.168.202.97\n" + "224.168.202.97\n" + "92.18.2.97\n" + "http://74.251.154.247/find-ip-address-of-web-site.html\n\n" + "74.201.154.247/find-ip-address-of-web-site.html\n\n" + "74.201.154.247\n\n" + "foo.com\n\n" + "http://92.18.2.97\n\n\n\n" + "asasasasasac31.23.53.122asasassasd\n\n" + "12312312312321.32.34.2312312312321\n\n" + "12.3423423432.234123123.123\n\n" + "31.134232131.231.34\n\n\n" + "SHOULD MATCH:\n\n" + "http://foo.com/blah_blah\n" + "http://foo.com/blah_blah/\n" + "http://foo.com/blah_blah_(wikipedia)\n" + "http://foo.com/blah_blah_(wikipedia)_(again)\n" + "http://www.example.com/wpstyle/?p=364\n" + "https://www.example.com/foo/?bar=baz&inga=42&quux\n" + "http://✪df.ws/123\n" + "http://userid:password@example.com:8080\n" + "http://userid:password@example.com:8080/\n" + "http://userid@example.com\n" + "http://userid@example.com/\n" + "http://userid@example.com:8080\n" + "http://userid@example.com:8080/\n" + "http://userid:password@example.com\n" + "http://userid:password@example.com/\n" + "http://142.42.1.1/\n" + "http://142.42.1.1:8080/\n" + "http://➡.ws/䨹\n" + "http://⌘.ws\n" + "http://⌘.ws/\n" + "http://foo.com/blah_(wikipedia)#cite-1\n" + "http://foo.com/blah_(wikipedia)_blah#cite-1\n" + "http://foo.com/unicode_(✪)_in_parens\n" + "http://foo.com/(something)?after=parens\n" + "http://☺.damowmow.com/\n" + "http://code.google.com/events/#&product=browser\n" + "http://j.mp\n" + "ftp://foo.bar/baz\n" + "http://foo.bar/?q=Test%20URL-encoded%20stuff\n" + "http://مثال.إختبار\n" + "http://例子.测试\n" + "http://उदाहरण.परीक्षा\n" + "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com\n" + "http://1337.net\n" + "http://a.b-c.de\n" + "http://223.255.255.254\n\n"; 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