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

/
/
si

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 = "<div class=\"(.*?) video-item\">(.*?)href=\"([^\"]*)\"(.*?)data-get-thumbs-url=\"([^\"]*)\"(.*?)alt=\"([^\"]*)\"(.*?)src='([^']*)'(.*?)<div class=\"timer hidden-xs\">(\\s*)<p>([0-9]*)(.*?)<\\/p><\\/div>(.*?)<div class=\"description\">(\\s*)<p>(.*?)<\\/p>(.*?)<p class=\"title-video\">(.*?)<\\/p>(.*?)<div class=\"infos-video\">(.*?)<p>Le ([0-9][0-9])\\/([0-9][0-9])\\/([0-9][0-9][0-9][0-9])<\\/p>(\\s*)<p>([0-9 ]*?)vues<\\/p>(.*?)<\\/div>(.*?)<div class=\"cat-video\">(\\s*)(.*?)(\\s*)<\\/div>(\\s*?)<\\/div>"; final String string = "\n" + " \n" + " <div class=\"col-md-3 col-sm-4 col-xs-6 video-item\">\n\n" + " <a target=\"_blank\" data-popunder-enabled href=\"/videos/show/1983/sandrine-teste-la-double.html\">\n" + " <div class=\"thumb-video\">\n" + " \n" + " <img class=\"videoThumb\"\n" + " data-get-thumbs-url=\"/video/1983/thumbnails_262x196.json\"\n" + " alt=\"Double pénétration, Double vaginale, Sodomie\"\n" + " src='http://m.tv2.cdn.jetm-tech.net/cache/4a/c5/4ac5ff7ae42612bfc68139740700ea0c.jpg'\n" + " />\n" + " \n" + " <div class=\"timer hidden-xs\"> <p>47 min</p></div>\n\n" + " <div class=\"description\">\n" + " <p>Notre équipe retrouve Sandrine devant le château de Blois pour constater, une fois de plus, que cette timide historienne de 31ans est une sacrée chaudasse ! \n" + "…</p>\n" + " </div>\n" + " </div>\n\n" + " <p class=\"title-video\"> Sandrine teste la double&nbsp;!</p>\n" + " <div class=\"infos-video\">\n" + " <p>Le 12/10/2015</p>\n" + " <p>1 876 156 vues</p>\n" + " </div>\n" + " </a>\n" + " <div class=\"cat-video\">\n" + " <p>Catégories : <a href=\"/tag/1/double-penetration.html\">Double pénétration</a>, <a href=\"/tag/2/double-vaginale.html\">Double vaginale</a>, <a href=\"/tag/8/sodomie.html\">Sodomie</a></p>\n" + " </div>\n\n" + " </div>\n" + " \n" + " <div class=\"col-md-3 col-sm-4 col-xs-6 video-item\">\n\n" + " <a target=\"_blank\" data-popunder-enabled href=\"/videos/show/1982/soizic-passe-un-entretien-dembauche.html\">\n" + " <div class=\"thumb-video\">\n" + " \n" + " <img class=\"videoThumb\"\n" + " data-get-thumbs-url=\"/video/1982/thumbnails_262x196.json\"\n" + " alt=\"Cougar, Scénario, Sodomie\"\n" + " src='http://m.tv2.cdn.jetm-tech.net/cache/cc/e5/cce55a7502d51aaefc049ee83334653c.jpg'\n" + " />\n" + " \n" + " <div class=\"timer hidden-xs\"> <p>30 min</p></div>\n\n" + " <div class=\"description\">\n" + " <p>Quand Soizic, 40ans, de Saint-Malo, et l&#39;ami Rick se font un petit plan un brin pervers...\n" + "Pour voir ses vidéos, mettez Soizic dans la recherche.\n" + "Parlez en …</p>\n" + " </div>\n" + " </div>\n\n" + " <p class=\"title-video\"> Soizic passe un entretien d'embauche&nbsp;!</p>\n" + " <div class=\"infos-video\">\n" + " <p>Le 11/10/2015</p>\n" + " <p>1 882 538 vues</p>\n" + " </div>\n" + " </a>\n" + " <div class=\"cat-video\">\n" + " <p>Catégories : <a href=\"/tag/23/cougar.html\">Cougar</a>, <a href=\"/tag/56/scenario.html\">Scénario</a>, <a href=\"/tag/8/sodomie.html\">Sodomie</a></p>\n" + " </div>\n\n" + " </div>\n" + " \n" + " <div class=\"col-md-3 col-sm-4 col-xs-6 video-item\">\n\n" + " <a target=\"_blank\" data-popunder-enabled href=\"/videos/show/1981/lola-se-libere.html\">\n" + " <div class=\"thumb-video\">\n" + " \n" + " <img class=\"videoThumb\"\n" + " data-get-thumbs-url=\"/video/1981/thumbnails_262x196.json\"\n" + " alt=\"Double pénétration, Sodomie, Trio HHF\"\n" + " src='http://m.tv2.cdn.jetm-tech.net/cache/f3/5b/f35b23b16f81588dda16702cec5ef284.jpg'\n" + " />\n" + " \n" + " <div class=\"timer hidden-xs\"> <p>42 min</p></div>\n\n" + " <div class=\"description\">\n" + " <p>Sa première vidéo a eu de telles vertus thérapeutiques que Lola surmonte désormais tous ses complexes et va même jusqu&#39;à nous entraîner chez un de ses nouveaux…</p>\n" + " </div>\n" + " </div>\n\n" + " <p class=\"title-video\"> Lola se libère&nbsp;!</p>\n" + " <div class=\"infos-video\">\n" + " <p>Le 10/10/2015</p>\n" + " <p>1 717 096 vues</p>\n" + " </div>\n" + " </a>\n" + " <div class=\"cat-video\">\n" + " <p>Catégories : <a href=\"/tag/1/double-penetration.html\">Double pénétration</a>, <a href=\"/tag/8/sodomie.html\">Sodomie</a>, <a href=\"/tag/21/trio-hhf.html\">Trio HHF</a></p>\n" + " </div>\n\n" + " </div>\n"; final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL | Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(string); if (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