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

/
/
g

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 = "(?=[\\r\\n]+)\\s*([0-9]+[\\/][^\\r\\n\\s])+\\s*[0-9][^\\r\\n]*[\\r\\n]+"; final String string = "WIRES\n" + "Wire Details Actions: Go Print Close\n" + "Rec'd Date/Time (EST) Sender ST Wire Type/Title Master Message # Deal Type\n\n" + " \n" + "RE: $ 437,025,000\n" + "CITY OF AURORA, COLORADO\n" + "ACTING BY AND THROUGH ITS UTILITY ENTERPRISE\n" + "FIRST LIEN WATER REFUNDING BONDS, SERIES 2016\n" + "(GREEN BONDS)\n" + " \n" + " \n" + " \n" + "LADIES AND GENTLEMEN:\n" + " \n" + "WE HAVE RECEIVED THE WRITTEN AWARD. TODAY, JULY 22ND WILL BE INITIAL TRADE DATE.\n" + "TIME OF FIRST EXECUTION IS 11:00AM EST.\n" + " \n" + " \n" + " MOODY'S: NR S&P: AA+ FITCH: AA+ \n" + " \n" + " DATED:08/16/2016 FIRST COUPON:02/01/2017\n" + " \n" + " DUE: 08/01 \n" + " \n" + " INITIAL TRADE DATE: 07/22/2016 @ 11:00AM Eastern\n" + " \n" + " \n" + " \n" + "MATURITY AMOUNT COUPON PRICE CUSIP \n" + "08/01/2020 2,350M 1.50% 0.83 051595AL0\n" + " (Approx. $ Price 102.603) \n" + "08/01/2021 4,855M 5.00% 0.97 051595AM8\n" + " (Approx. $ Price 119.462) \n" + "08/01/2022 7,565M 5.00% 1.13 051595AN6\n" + " (Approx. $ Price 122.238) \n" + "08/01/2023 10,410M 5.00% 1.28 051595AP1\n" + " (Approx. $ Price 124.689) \n" + "08/01/2024 1,625M 3.00% 1.40 051595AQ9\n" + " (Approx. $ Price 112.009) \n" + "08/01/2024 9,305M 5.00% 1.40 051595BE5\n" + " (Approx. $ Price 127.021) \n" + "08/01/2025 11,445M 5.00% 1.52 051595AR7\n" + " (Approx. $ Price 129.042) \n" + "08/01/2026 4,000M 4.00% 1.65 051595AS5\n" + " (Approx. $ Price 121.498) \n" + "08/01/2026 8,015M 5.00% 1.65 051595BJ4\n" + " (Approx. $ Price 130.646) \n" + "08/01/2027 12,015M 5.00% 1.76 051595AT3\n" + " (Approx. $ Price PTC 08/01/2026 129.476 Approx. YTM 1.992) \n" + "08/01/2028 12,615M 5.00% 1.87 051595BF2\n" + " (Approx. $ Price PTC 08/01/2026 128.318 Approx. YTM 2.281) \n" + "08/01/2029 13,245M 5.00% 1.93 051595AU0\n" + " (Approx. $ Price PTC 08/01/2026 127.691 Approx. YTM 2.487) \n" + "08/01/2030 13,905M 5.00% 1.98 051595BG0\n" + " (Approx. $ Price PTC 08/01/2026 127.172 Approx. YTM 2.657) \n" + "08/01/2031 14,600M 5.00% 2.03 051595AV8\n" + " (Approx. $ Price PTC 08/01/2026 126.655 Approx. YTM 2.806) \n" + "08/01/2032 6,045M 4.00% 2.33 051595AW6\n" + " (Approx. $ Price PTC 08/01/2026 114.764 Approx. YTM 2.843) \n" + "08/01/2032 8,835M 5.00% 2.08 051595BM7\n" + " (Approx. $ Price PTC 08/01/2026 126.141 Approx. YTM 2.936) \n" + "08/01/2033 15,565M 5.00% 2.13 051595AX4\n" + " (Approx. $ Price PTC 08/01/2026 125.629 Approx. YTM 3.053) \n" + "08/01/2034 16,345M 5.00% 2.18 051595AY2\n" + " (Approx. $ Price PTC 08/01/2026 125.119 Approx. YTM 3.157) \n" + "08/01/2035 17,160M 5.00% 2.22 051595AZ9\n" + " (Approx. $ Price PTC 08/01/2026 124.714 Approx. YTM 3.244) \n" + "08/01/2036 18,020M 5.00% 2.26 051595BA3\n" + " (Approx. $ Price PTC 08/01/2026 124.310 Approx. YTM 3.324) \n" + " \n" + "08/01/2041 40,000M 3.00% 2.90 051595BK1\n" + " (Approx. $ Price PTC 08/01/2026 100.858 Approx. YTM 2.951) \n" + " \n" + "08/01/2041 62,915M 5.00% 2.32 051595BD7\n" + " (Approx. $ Price PTC 08/01/2026 123.706 Approx. YTM 3.559) \n" + " \n" + "08/01/2046 45,000M 2.00% 100.00 051595BB1\n" + "**STEP COUPON \n" + " \n" + "08/01/2046 25,000M 3.00% 2.95 051595BL9\n" + " (Approx. $ Price PTC 08/01/2026 100.427 Approx. YTM 2.978) \n" + " \n" + "08/01/2046 5,000M 4.00% 2.62 051595BH8\n" + " (Approx. $ Price PTC 08/01/2026 112.026 Approx. YTM 3.360) \n" + " \n" + "08/01/2046 51,190M 5.00% 2.37 051595BC9\n" + " (Approx. $ Price PTC 08/01/2026 123.206 Approx. YTM 3.710) \n" + " \n" + " ---------------------------------------\n" + " \n" + "CALL FEATURES: Optional call in 08/01/2026 @ 100.00\n" + " \n" + "EXCEPT:\n" + " 08/01/2046 Optional call in 08/01/2019 @ 100.00 Coupon: 2.000\n" + "**THE STEP COUPON BONDS WILL BEAR INTEREST EACH PERIOD AS FOLLOWS:\n" + " \n" + "FROM TO (AND INCLUDING) INTEREST RATE\n" + "--------- ------------------ -------------\n" + "08/16/2016 07/31/2019 2.000%\n" + "08/01/2019 07/31/2026 2.250%\n" + "08/01/2026 07/31/2031 3.500%\n" + "08/01/2031 07/31/2041 4.500%\n" + "08/01/2041 08/01/2046 5.000%\n" + " \n" + " ---------------------------------------\n" + " \n" + " Sinking Fund Schedule\n" + " \n" + "2041 Term Bond\n" + " \n" + "08/01/2037 7,535M\n" + "08/01/2038 7,760M\n" + "08/01/2039 7,995M\n" + "08/01/2040 8,230M\n" + "08/01/2041 8,480M\n" + " \n" + " Sinking Fund Schedule\n" + " \n" + "2041 Term Bond\n" + " \n" + "08/01/2037 11,385M\n" + "08/01/2038 11,955M\n" + "08/01/2039 12,550M\n" + "08/01/2040 13,185M\n" + "08/01/2041 13,840M\n" + " \n" + " Sinking Fund Schedule\n" + " \n" + "2046 Term Bond\n" + " \n" + "08/01/2042 8,145M\n" + "08/01/2043 8,550M\n\n" + "08/01/2044 8,980M\n" + "08/01/2045 9,425M\n" + "08/01/2046 9,900M\n" + " \n" + " Sinking Fund Schedule\n" + " \n" + "2046 Term Bond\n" + " \n" + "08/01/2042 4,710M\n" + "08/01/2043 4,850M\n" + "08/01/2044 4,995M\n" + "08/01/2045 5,145M\n" + "08/01/2046 5,300M\n" + " \n" + " Sinking Fund Schedule\n" + " \n" + "2046 Term Bond\n" + " \n" + "08/01/2042 920M\n" + "08/01/2043 960M\n" + "08/01/2044 1,000M\n" + "08/01/2045 1,040M\n" + "08/01/2046 1,080M\n" + " \n" + " Sinking Fund Schedule\n" + " \n" + "2046 Term Bond\n" + " \n" + "08/01/2042 9,265M\n" + "08/01/2043 9,730M\n" + "08/01/2044 10,210M\n" + "08/01/2045 10,725M\n" + "08/01/2046 11,260M\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "PRIORITY OF ORDERS:\n" + "1. Net Designated\n" + "(Except if an investor is affiliated with a syndicate member in which case the\n" + " economics will be reallocated among the other managers. Please contact the\n" + " Senior Manager.)\n" + "2. Individual Colorado Retail\n" + "3. Individual National Retail\n" + "4. Member\n" + " \n" + " \n" + "\"Individual Colorado Retail Order\" is defined as an order up to $1,000,000 placed on\n" + "behalf of an individual in Colorado. Larger Individual Colorado Retail Orders will be\n" + "accepted at the sole discretion of the City. All Individual Colorado Retail Orders must\n" + "include account numbers and zip codes.\n" + " \n" + "An \"Individual National Retail Order\" is defined as an order up to $1,000,000 placed on\n" + "behalf of an individual outside of Colorado. Larger Individual National Retail Orders\n" + "will be accepted at the sole discretion of the City. All Individual National Retail\n" + "Orders must include account numbers and zip codes.\n" + " \n" + " \n" + "Priority Policy:\n" + " \n" + "Morgan Stanley & Co. must receive 50% of each designation.\n" + " \n" + "RBC Capital Markets must receive at least 20% of each designation.\n" + " \n" + "Bank of America Merrill Lynch and Wells Fargo Securities must each be designated at least\n" + "10%.\n" + " \n" + "No firm may receive more than 50% of each designation.\n" + " \n" + " \n" + " \n" + "The compliance addendum MSRB Rule G-11 will apply.\n" + " \n" + " \n" + "The Award is expected on Thursday, July 21, 2016 at 5:10PM Eastern .\n" + " \n" + "Delivery is firm for Tuesday, August 16, 2016.\n" + " \n" + "This issue is book entry only. This issue is clearing through DTC.\n" + " \n" + " \n" + " \n" + "Award: 07/21/2016 \n" + "Award Time: 5:10PM Eastern \n" + "Delivery: 08/16/2016 (Firm)\n" + "Initial trade: 07/22/2016 \n" + "Date of Execution: 07/22/2016 \n" + "Time of Execution: 11:00AM Eastern \n" + " \n" + " \n" + " \n" + "Electronic copies of the Preliminary Official Statement can be accessed via the following\n" + "link:\n" + "http://www.meritos.com/cgi-bin/disclaimer.pl?Did=2225\n" + " \n" + "Morgan Stanley & Co. LLC \n" + "RBC Capital Markets \n" + "Bank of America Merrill Lynch \n" + "Wells Fargo Securities (trade name for Wells Fargo \n" + "Bank N.A. Municipal Products Group) \n" + " \n" + "By: Morgan Stanley & Co. LLC New York, NY\n" + " Close\n\n" + "Terms and Conditions of Use and Privacy Statement © 2016 Ipreo. All rights reserved.\n"; final Pattern pattern = Pattern.compile(regex); 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