Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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

/
/

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 = "\\/\\*(.|\\n|\\r)*\\*\\/"; final String string = "\n" + "package es.elcorteingles.ns.integrations.schema.omnistoreordernotification._2_0;\n\n" + "import javax.xml.bind.annotation.XmlAccessType;\n" + "import javax.xml.bind.annotation.XmlAccessorType;\n" + "import javax.xml.bind.annotation.XmlType;\n\n\n" + "/**\n" + " * Contiene informacion del coste a nivel de\n" + " * ShippingGroup.\n" + " * - Importe total.\n" + " * - Importe pendiente a cobrar.\n" + " * - Importe\n" + " * del gasto de envío\n" + " * \n" + " * \n" + " * <p>Java class for ShippingGroupPriceInfoType complex type.\n" + " * \n" + " * <p>The following schema fragment specifies the expected content contained within this class.\n" + " * \n" + " * <pre>\n" + " * &lt;complexType name=\"ShippingGroupPriceInfoType\">\n" + " * &lt;complexContent>\n" + " * &lt;restriction base=\"{http://www.w3.org/2001/XMLSchema}anyType\">\n" + " * &lt;sequence>\n" + " * &lt;element name=\"totalCost\" type=\"{http://www.elcorteingles.es/ns/integrations/schema/OmniStoreOrderNotification/2_0}AmountType\" minOccurs=\"0\"/>\n" + " * &lt;element name=\"pendingCost\" type=\"{http://www.elcorteingles.es/ns/integrations/schema/OmniStoreOrderNotification/2_0}AmountType\" minOccurs=\"0\"/>\n" + " * &lt;element name=\"shippingCost\" type=\"{http://www.elcorteingles.es/ns/integrations/schema/OmniStoreOrderNotification/2_0}AmountType\" minOccurs=\"0\"/>\n" + " * &lt;element name=\"groupDiscountsAmount\" type=\"{http://www.elcorteingles.es/ns/integrations/schema/OmniStoreOrderNotification/2_0}AmountType\" minOccurs=\"0\"/>\n" + " * &lt;element name=\"totalNetAmount\" type=\"{http://www.elcorteingles.es/ns/integrations/schema/OmniStoreOrderNotification/2_0}AmountType\" minOccurs=\"0\"/>\n" + " * &lt;/sequence>\n" + " * &lt;/restriction>\n" + " * &lt;/complexContent>\n" + " * &lt;/complexType>\n" + " * </pre>\n" + " * \n" + " * \n" + " */\n" + "@XmlAccessorType(XmlAccessType.FIELD)\n" + "@XmlType(name = \"ShippingGroupPriceInfoType\", propOrder = {\n" + " \"totalCost\",\n" + " \"pendingCost\",\n" + " \"shippingCost\",\n" + " \"groupDiscountsAmount\",\n" + " \"totalNetAmount\"\n" + "})\n" + "public class ShippingGroupPriceInfoType {\n\n" + " protected AmountType totalCost;\n" + " protected AmountType pendingCost;\n" + " protected AmountType shippingCost;\n" + " protected AmountType groupDiscountsAmount;\n" + " protected AmountType totalNetAmount;\n\n" + " /**\n" + " * Gets the value of the totalCost property.\n" + " * \n" + " * @return\n" + " * possible object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public AmountType getTotalCost() {\n" + " return totalCost;\n" + " }\n\n" + " /**\n" + " * Sets the value of the totalCost property.\n" + " * \n" + " * @param value\n" + " * allowed object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public void setTotalCost(AmountType value) {\n" + " this.totalCost = value;\n" + " }\n\n" + " /**\n" + " * Gets the value of the pendingCost property.\n" + " * \n" + " * @return\n" + " * possible object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public AmountType getPendingCost() {\n" + " return pendingCost;\n" + " }\n\n" + " /**\n" + " * Sets the value of the pendingCost property.\n" + " * \n" + " * @param value\n" + " * allowed object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public void setPendingCost(AmountType value) {\n" + " this.pendingCost = value;\n" + " }\n\n" + " /**\n" + " * Gets the value of the shippingCost property.\n" + " * \n" + " * @return\n" + " * possible object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public AmountType getShippingCost() {\n" + " return shippingCost;\n" + " }\n\n" + " /**\n" + " * Sets the value of the shippingCost property.\n" + " * \n" + " * @param value\n" + " * allowed object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public void setShippingCost(AmountType value) {\n" + " this.shippingCost = value;\n" + " }\n\n" + " /**\n" + " * Gets the value of the groupDiscountsAmount property.\n" + " * \n" + " * @return\n" + " * possible object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public AmountType getGroupDiscountsAmount() {\n" + " return groupDiscountsAmount;\n" + " }\n\n" + " /**\n" + " * Sets the value of the groupDiscountsAmount property.\n" + " * \n" + " * @param value\n" + " * allowed object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public void setGroupDiscountsAmount(AmountType value) {\n" + " this.groupDiscountsAmount = value;\n" + " }\n\n" + " /**\n" + " * Gets the value of the totalNetAmount property.\n" + " * \n" + " * @return\n" + " * possible object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public AmountType getTotalNetAmount() {\n" + " return totalNetAmount;\n" + " }\n\n" + " /**\n" + " * Sets the value of the totalNetAmount property.\n" + " * \n" + " * @param value\n" + " * allowed object is\n" + " * {@link AmountType }\n" + " * \n" + " */\n" + " public void setTotalNetAmount(AmountType value) {\n" + " this.totalNetAmount = value;\n" + " }\n\n" + "}\n"; final String subst = ""; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceFirst(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