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

/
/
gis

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 = "^(?:[[:^print:][:cntrl:]\\s]|GIF89.{0,20})*<\\?(?:php)?\\s*\\/\\/open\\s*templates\\/yours\\.php.{0,180}?yourlinkscam.{0,100}?rand\\(\\d+,.{0,2500}?your\\s*account\\s*will\\s*be\\s*limited\\s*over\\s*24\\s*h.{0,200}?unauthorised\\s*account\\s*access.{0,220}?Click\\s*the\\s*link\\s*Below.{0,80}Confirm\\s*Your\\s*Account.{0,450}?paypal\\s*inc\\..{0,300}?paypal\\s*corporation(?:[^;]+;\\s*)?\\s*if\\(\\!empty\\(\\$_GET\\[[\"']view['\"]\\]\\)\\)\\{echo\\s*\\$html(?:[^>]+>\\s*)?$"; final String string = "<?php\n" + "//open templates/Yours.php with a text editor copy paste your html code in $html between the 2 ' and change all ' in your html to \\' and href=\"http://yourlinkscam\" to href=\"'.$var.'\" \n\n" + "ini_set(\"output_buffering\",4096);\n" + "$IDK = rand(00000000000, 99999999999).time();\n" + "error_reporting(0);\n" + "$html='\n" + "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;\">\n" + "<style type=\"text/css\">body { width: 100% !important;}</style>\n" + " </head>\n\n\n" + " \n" + " <table width=\"0\" border=\"0\">\n" + " <tbody><tr>\n" + " <td> <div>\n" + " <table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">\n" + " <tbody>\n" + " <tr>\n" + " <td style=\" BACKGROUND: #ffffff; LINE-HEIGHT: 22px;border-radius: 10px 10px 10px 10px\">\n\n" + " \n" + " \n" + " \n\n" + " <center><td>\n" + "<div style=\"FONT-SIZE:14px;FONT-FAMILY:Arial;COLOR:#747474\">\n" + "<p align=\"left\">\n" + "</p><div style=\"FONT-SIZE:10px;FONT-FAMILY:Arial black;COLOR:#828282;padding-left:30px\">\n" + "<center><p style=\"FONT-SIZE:28px\"><strong><em><font color=\"#003084\">P<span><font>a</font></span>y</font><font color=\"#0098db\">Pal</font></em></strong></center>\n" + "</p>\n\n" + "</div>\n" + "<p></p>\n" + "</div>\n" + "</td></center>\n" + " \n" + " \n" + " \n" + " </sub></font></p></div></p>\n" + " \n" + " </div>\n" + " </td>\n" + " </tr>\n" + " </tbody>\n" + " </table>\n\n" + " </td>\n" + " </tr>\n" + " </tbody>\n" + " </table>\n" + " </div>\n" + "<div><table cellspacing=\"0\" cellpadding=\"0\" width=\"0\" border=\"0\">\n" + " <tbody>\n" + " <tr>\n" + " <td style=\" BACKGROUND: #F3F3FF; ; LINE-HEIGHT: 22px\">\n" + " <table cellspacing=\"0\" cellpadding=\"0\" width=\"600\" align=\"left\" border=\"0\">\n" + " <tbody>\n" + " <tr>\n" + " <td>\n" + " <div>\n\n" + "<br />\n" + "<br />\n" + "<br />\n" + "<td style=\"PADDING-TOP:15px\">\n" + "<div style=\"FONT-SIZE:15px;FONT-FAMILY:Arial;COLOR:#585858;margin-left:10px;margin-right:30px\">\n" + "<center><p style=\"font-family:Helvetica Neue Light,Helvetica,Arial,sans-serif;font-size:20px;color:#009cde\">Your Account will be limited over 24 h if you dont\n" + "confirm it .</p></center>\n" + "<br>\n" + "<p>\n" + "<strong>why my Account will Be limited ?</p></strong>\n" + "<center><em><li><ins>unauthorised account access From 59.56.111.253 . China-CN</ins></em></p></li>\n" + "<br>\n" + "Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0\n" + "<br>\n" + "<br> \n" + "<span style=\"color: #808080;\"><strong>Click the link Below and login then follow steps to Confirm Your Account :</strong></span><br /><br /><br><a onclick=\"return true\" href=\"'.$var.'\" style=\"FONT-SIZE:14px;FONT-FAMILY:Arial;WIDTH:250px;COLOR:#fff;TEXT-ALIGN:center;DISPLAY:inline-block;BACKGROUND-COLOR:#16aeff;border-radius:7px;line-height:28px\"><strong>Confirm My Account\n" + "</strong> </a><br /> <br /> <br /> <br /> <span style=\"font-size: 10px; font-family: Arial, Verdena;\"> <em>PayPal Inc. : PayPal Corporate Center, 100 North Tryon Street, Charlotte, NC 28255. \n" + "<br/>\n" + "<br/>\n" + "You can un-subscribe to security alerts by configuring your online account. \n" + "We are sending this email to provide support for your personal account. <br /> <br />&#169; 2017 PayPal Corporation. All rights reserved</em> </span> </li>';\n" + "if(!empty($_GET[\"view\"])){echo $html;}\n" + "?>"; final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); 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