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
No Match

/
/
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 = "(&[A-Za-z]+?;)|(<.+?>)|(<\\/\\w+>)|([\\w-]+)|([ ~!@#$%^&*()+=?:;\"\\{\\}\\[\\]|,.\\\\/]+)"; final String string = "This is more<p>Post server upgrade test on 9/13</p><p>Testing c360 release</p><p>&nbsp;</p><p><span title=\\\"Deleted by Chris Courtney - 12/16/2015 3:22pm\\\" class=\\\"del cts-1 non-editable\\\" data-mce-contenteditable=\\\"false\\\" data-time=\\\"1450297379217\\\" data-username=\\\"Chris Courtney\\\" data-userid=\\\"4642\\\" data-cid=\\\"4\\\">wifi</span><span title=\\\"Inserted by Chris Courtney - 12/16/2015 3:23pm\\\" class=\\\"ins cts-1\\\" data-time=\\\"1450297385376\\\" data-username=\\\"Chris Courtney\\\" data-userid=\\\"4642\\\" data-cid=\\\"8\\\">Life&nbsp;Preserver&nbsp;will</span> save <span title=\\\"Inserted by Chris Courtney - 12/16/2015 3:23pm\\\" class=\\\"ins cts-1\\\" data-time=\\\"1450297399510\\\" data-username=\\\"Chris Courtney\\\" data-userid=\\\"4642\\\" data-cid=\\\"28\\\">if&nbsp;the&nbsp;</span>internet cut<span title=\\\"Inserted by Chris Courtney - 12/16/2015 3:23pm\\\" class=\\\"ins cts-1\\\" data-time=\\\"1450297404606\\\" data-username=\\\"Chris Courtney\\\" data-userid=\\\"4642\\\" data-cid=\\\"35\\\">s&nbsp;</span>out<span title=\\\"Inserted by Chris Courtney - 12/16/2015 3:23pm\\\" class=\\\"ins cts-1\\\" data-time=\\\"1450297409071\\\" data-username=\\\"Chris Courtney\\\" data-userid=\\\"4642\\\" data-cid=\\\"42\\\">.</span><span title=\\\"Deleted by Chris Courtney - 12/16/2015 3:23pm\\\" class=\\\"del cts-1 non-editable\\\" data-mce-contenteditable=\\\"false\\\" data-time=\\\"1450297406872\\\" data-username=\\\"Chris Courtney\\\" data-userid=\\\"4642\\\" data-cid=\\\"37\\\"> test</span></p><p>&nbsp;</p><p>The Subject Property is owned by the&nbsp;Federal Deposit Insurance Corporation (FDIC) and consists of 10 Acres acres and is located&nbsp;on the [N/E/S/W] side of 440 Wheelers Farms Road, approximately&nbsp;[###] feet [N/E/S/W] of the intersection of&nbsp;between[STREETNAME] and [].porperty ocne upon a tmie The Subject Property is not&nbsp;currently occupied by [BRIEFLY DESCRIBE BUILDING, OCCUPANT AND USE]. This is me entering new text into 2.1. This is a bullet. Type text 123 spelling</p><p>&nbsp;</p><p>The Subject Property is owned by the <span title=\\\"Deleted by Chris Courtney\\\" class=\\\"trackChanges\\\">Federal Deposit Insurance Corporation</span> (FDIC) and consists of 10 Acres acres and is located on the [N/E/S/W] side of 440 Wheelers Farms Road, approximately [###] feet [N/E/S/W] of the intersection of between[STREETNAME] and []. The Subject Property is not currently occupied by [BRIEFLY DESCRIBE BUILDING, OCCUPANT AND USE]. This is me entering new text into 2.1.</p><p>&nbsp;</p><p>This is a bullet.EDR order right after (discussed geocoding concerns, we're all set there) test</p><p>&nbsp;</p><p>Type text 123 spelling The Subject Property is owned by the Federal Deposit Insurance Corporation (FDIC) and consists of 10 Acres acres and is located on the [N/E/S/W] side of 440 Wheelers Farms Road, approximately [###] feet [N/E/S/W] of the intersection of<span title=\\\"Added by Chris Courtney\\\" class=\\\"trackChanges\\\">/</span><span title=\\\"Deleted by Chris Courtney\\\" class=\\\"trackChanges\\\">&nbsp;</span>between[STREETNAME] and [].</p><p>&nbsp;</p><p>&nbsp;</p><p>The Subject Property is not currently occupied by [BRIEFLY DESCRIBE BUILDING, OCCUPANT AND USE].</p><p>This is me entering new text into 2.1. test</p><p>&nbsp;</p><p>This is a bullet.</p><p>&nbsp;</p><p>Type text 123 spellingThe Subject Property is owned by the Federal Deposit Insurance Corporation (FDIC) and consists of 10 Acres acres and is located on the [N/E/S/W] side of 440 Wheelers Farms Road, approximately [###] feet [N/E/S/W] of the intersection of between[STREETNAME] and [].</p><p>&nbsp;</p><p>&nbsp;</p><p>The Subject Property is not currently occupied by [BRIEFLY DESCRIBE BUILDING, OCCUPANT AND USE].</p><p>This is me entering new text into 2.1.</p><p>&nbsp;</p><p>This is a bullet.</p><p>&nbsp;</p><p>Type text 123 spellingThe Subject Property is owned by the Federal Deposit Insurance Corporation (FDIC) and consists of 10 Acres acres and is located on the [N/E/S/W] side of 440 Wheelers Farms Road, approximately [###] feet [N/E/S/W] of the intersection of between[STREETNAME] and [].</p><p>&nbsp;</p><p>&nbsp;</p><p>The Subject Property is not currently occupied by [BRIEFLY DESCRIBE BUILDING, OCCUPANT AND USE].</p><p>This is me entering new text into 2.1.</p><p>&nbsp;</p><p>This is a bullet.</p><p>&nbsp;</p><p>Type text 123 spellingThe Subject Property is owned by the Federal Deposit Insurance Corporation (FDIC) and consists of 10 Acres acres and is located on the [N/E/S/W] side of 440 Wheelers Farms Road, approximately [###] feet [N/E/S/W] of the intersection of between[STREETNAME] and [].</p><p>&nbsp;</p><p>&nbsp;</p><p>The Subject Property is not currentl<span title=\\\"Inserted by Chris Courtney - 06/12/2015 2:40pm\\\" class=\\\"ins cts-1\\\" data-time=\\\"1434134407587\\\" data-username=\\\"Chris Courtney\\\" data-userid=\\\"4642\\\" data-cid=\\\"2\\\">y</span> <span title=\\\"Inserted by Chris Courtney - 06/12/2015 2:40pm\\\" class=\\\"ins cts-1\\\" data-time=\\\"1434134414659\\\" data-username=\\\"Chris Courtney\\\" data-userid=\\\"4642\\\" data-cid=\\\"3\\\">this is a test.&nbsp;</span>occupied by [BRIEFLY DESCRIBE BUILDING, OCCUPANT AND USE].</p><p>This is me entering new text into 2.1.</p><p>&nbsp;</p><p>This is a bullet.</p><p>&nbsp;</p><p>Type text 123 spelling</p><p>&nbsp;</p><p>2014&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Schultz Motors of Milan<br> 2009-2008&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dive Rite<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Procom Driving Services<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Schultz Motors of Milan - New and Used<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Schultz Motors of Milan -Part and Service<br> 2004-2003&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Adventure Driving<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dive Rite<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Procom Driving Services<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Schultz Motors of Milan - New and Used<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Schultz Motors of Milan -Part and Service<br> 1999-1998&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dive Rite<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Procom Driving Services<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Schultz Motors of Milan - New and Used<br> 1994-1983&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Schultz Motors<br> 1979-1967&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bruckner Oldsmobile</p><p>&nbsp;</p><p>&nbsp;132543467</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>Heh?"; final String subst = "|"; 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