Regular Expressions 101

Save & Share

  • Regex Version: ver. 9
  • 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
No Match

/
/
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 = "^--.*--$|=|('|\").*?\\1|[^\\t\\n\\f \\/>\"'=]+"; final String string = "[2021-11-24 16:26:27,931] [dc4-10.123.66.197-http-bio-8080-exec-1500_LADC_72E18BC06AF39AA1FCC7A95DF068E068] [INFO] [LoggingInInterceptor] [] [Inbound Message\n" + "----------------------------\n" + "ID: 5520137\n" + "Response-Code: 200\n" + "Encoding: UTF-8\n" + "Content-Type: text/xml;charset=utf-8\n" + "Headers: {connection=[keep-alive], Content-Length=[3351], Content-Security-Policy=[default-src * 'unsafe-inline' 'unsafe-eval'; script-src * 'unsafe-inline' 'unsafe-eval'; connect-src * 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src *; style-src * 'unsafe-inline';], content-type=[text/xml;charset=utf-8], Date=[Wed, 24 Nov 2021 16:26:27 GMT], Keep-Alive=[timeout=30], Referrer-Policy=[origin-when-cross-origin], Server=[SWS], SOAPAction=[\"\"], Strict-Transport-Security=[max-age=31536000], X-Content-Type-Options=[nosniff], X-Frame-Options=[SAMEORIGIN], X-XSS-Protection=[1; mode=block]}\n" + "Payload: <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<soap-env:Envelope xmlns:soap-env=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap-env:Header><eb:MessageHeader xmlns:eb=\"http://www.ebxml.org/namespaces/messageHeader\" eb:version=\"1.0\" soap-env:mustUnderstand=\"1\"><eb:From><eb:PartyId eb:type=\"URI\">123123</eb:PartyId></eb:From><eb:To><eb:PartyId eb:type=\"URI\">99999</eb:PartyId></eb:To><eb:CPAId>LA</eb:CPAId><eb:ConversationId>LADC_72E18BC06AF39AA1FCC7A95DF068E068</eb:ConversationId><eb:Service>SabreCommand</eb:Service><eb:Action>SabreCommandLLSRS</eb:Action><eb:MessageData><eb:MessageId>2651654591878281621</eb:MessageId><eb:Timestamp>2021-11-24T16:26:27</eb:Timestamp><eb:RefToMessageId>mid:2021-11-24T16:26:27@sabre.com</eb:RefToMessageId></eb:MessageData></eb:MessageHeader><wsse:Security xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/12/secext\"><wsse:BinarySecurityToken valueType=\"String\" EncodingType=\"wsse:Base64Binary\">Shared/IDL:IceSess\\/SessMgr:1\\.0.IDL/Common/!ICESMS\\/RESE!ICESMSLB\\/RES.LB!XXXXXXXXX9844!1410!261</wsse:BinarySecurityToken></wsse:Security></soap-env:Header><soap-env:Body><SabreCommandLLSRS xmlns=\"http://webservices.sabre.com/sabreXML/2003/07\" EchoToken=\"String\" TimeStamp=\"2021-11-24T16:26:27\" Target=\"Production\" Version=\"2003A.TsabreXML1.6.1\" SequenceNmbr=\"1\" PrimaryLangID=\"en-us\" AltLangID=\"en-us\">\n" + " <Response><![CDATA[CZMWQP]]><![CDATA[\n" + " 1.1SEREY/ANTOINE]]><![CDATA[\n" + " 1 AF1318V 24DEC F CDGFRA HK1 1525 1645 /RLAF*3AL3UX /E]]><![CDATA[\n" + " /OPERATED BY HOP]]><![CDATA[\n" + " 2 LA8071L 24DEC F FRAGRU HK1 2015 0420 25DEC J /E]]><![CDATA[\n" + " /OPERATED BY LATAM AIRLINES BRASIL]]><![CDATA[\n" + " 3 LA4777L 25DEC J GRUCWB HK1 0820 0925 /E]]><![CDATA[\n" + " /OPERATED BY LATAM AIRLINES BRASIL]]><![CDATA[\n" + "TKT/TIME LIMIT]]><![CDATA[\n" + " 1.T-28OCT-UHN5SHT]]><![CDATA[\n" + " 2.TE 0452159694657 SEREY/A UHN5SHT 1448/28OCT]]><![CDATA[\n" + "VCR COUPON DATA EXISTS *VI TO DISPLAY]]><![CDATA[\n" + "PHONES]]><![CDATA[\n" + " 1.HDQ33-33-762493204-M]]><![CDATA[\n" + "PASSENGER EMAIL DATA EXISTS *PE TO DISPLAY ALL]]><![CDATA[\n" + "PRICE QUOTE RECORD EXISTS - *PQS]]><![CDATA[\n" + "LA FACTS]]><![CDATA[\n" + " 1.SSR FOID LA HK1/PPFR15DC33906]]><![CDATA[\n" + " 2.OSI VENTA WWW.LAN.COM]]><![CDATA[\n" + " 3.SSR ADTK LA TO AF BY 31OCT 1200 HDQ OTHERWISE WILL BE XLD]]><![CDATA[\n" + " 4.SSR LAXP LA 8071L24DEC/LATAM XP USER NN1 ]]><![CDATA[\n" + " 6.SSR BRND LA 8071L24DEC/SL ]]><![CDATA[\n" + " 7.SSR LAXP LA 4777L25DEC/LATAM XP USER NN1 ]]><![CDATA[\n" + " 9.SSR BRND LA 4777L25DEC/SL ]]><![CDATA[\n" + "GENERAL FACTS]]><![CDATA[\n" + " 1.SSR FOID AF HK1/PPFR15DC33906]]><![CDATA[\n" + " 2.OSI YY VENTA WWW.LAN.COM]]><![CDATA[\n" + " 3.SSR OTHS AF LAXP]]><![CDATA[\n" + " 4.SSR OTHS AF LAXP]]><![CDATA[\n" + " 6.SSR OTHS AF LAXP]]><![CDATA[\n" + " 7.OSI LA SC.REAC 0228/31OCT21]]><![CDATA[\n" + " 8.SSR OTHS AF LAXP]]><![CDATA[\n" + " 9.SSR OTHS AF LAXP]]><![CDATA[\n" + "REMARKS]]><![CDATA[\n" + " 1.H-ID VENTA WWW.1646474003]]><![CDATA[\n" + " 2.H-LANCOM PAYMENT ATTEMPT]]><![CDATA[\n" + " 4.H-PLS CHK POSS DUPE OR LAN WILL CNL AFTER 12 HRS]]><![CDATA[\n" + " 5.H-PLS ADV TKT NBR BEFORE 31OCT21 1256 UHN LT OR AUTO CNL]]><![CDATA[\n" + " 6.H-SERVICE FEE EUR0.00/P1]]><![CDATA[\n" + " 7.H-IDVENTAPAGO WWW.1646474983]]><![CDATA[\n" + " 8.PNR WORKED ARU]]><![CDATA[\n" + " 9.NO ACTIONABLE TICKETS]]><![CDATA[\n" + " 10.NO ACTIONABLE TICKETS]]><![CDATA[\n" + "OAC - LA UHN LW 2049849 ]]><![CDATA[\n" + "UHN-UHN-LW.UHN5SHT 0656/28OCT21 CZMWQP H]]></Response>\n" + "</SabreCommandLLSRS></soap-env:Body></soap-env:Envelope>"; 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