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

const regex = /^--.*--$|=|('|").*?\1|[^\t\n\f \/>"'=]+/g; // Alternative syntax using RegExp constructor // const regex = new RegExp('^--.*--$|=|(\'|").*?\\1|[^\\t\\n\\f \\\/>"\'=]+', 'g') const str = `[2021-11-24 16:26:27,931] [dc4-10.123.66.197-http-bio-8080-exec-1500_LADC_72E18BC06AF39AA1FCC7A95DF068E068] [INFO] [LoggingInInterceptor] [] [Inbound Message ---------------------------- ID: 5520137 Response-Code: 200 Encoding: UTF-8 Content-Type: text/xml;charset=utf-8 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]} Payload: <?xml version="1.0" encoding="UTF-8"?> <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"> <Response><![CDATA[CZMWQP]]><![CDATA[ 1.1SEREY/ANTOINE]]><![CDATA[ 1 AF1318V 24DEC F CDGFRA HK1 1525 1645 /RLAF*3AL3UX /E]]><![CDATA[ /OPERATED BY HOP]]><![CDATA[ 2 LA8071L 24DEC F FRAGRU HK1 2015 0420 25DEC J /E]]><![CDATA[ /OPERATED BY LATAM AIRLINES BRASIL]]><![CDATA[ 3 LA4777L 25DEC J GRUCWB HK1 0820 0925 /E]]><![CDATA[ /OPERATED BY LATAM AIRLINES BRASIL]]><![CDATA[ TKT/TIME LIMIT]]><![CDATA[ 1.T-28OCT-UHN5SHT]]><![CDATA[ 2.TE 0452159694657 SEREY/A UHN5SHT 1448/28OCT]]><![CDATA[ VCR COUPON DATA EXISTS *VI TO DISPLAY]]><![CDATA[ PHONES]]><![CDATA[ 1.HDQ33-33-762493204-M]]><![CDATA[ PASSENGER EMAIL DATA EXISTS *PE TO DISPLAY ALL]]><![CDATA[ PRICE QUOTE RECORD EXISTS - *PQS]]><![CDATA[ LA FACTS]]><![CDATA[ 1.SSR FOID LA HK1/PPFR15DC33906]]><![CDATA[ 2.OSI VENTA WWW.LAN.COM]]><![CDATA[ 3.SSR ADTK LA TO AF BY 31OCT 1200 HDQ OTHERWISE WILL BE XLD]]><![CDATA[ 4.SSR LAXP LA 8071L24DEC/LATAM XP USER NN1 ]]><![CDATA[ 6.SSR BRND LA 8071L24DEC/SL ]]><![CDATA[ 7.SSR LAXP LA 4777L25DEC/LATAM XP USER NN1 ]]><![CDATA[ 9.SSR BRND LA 4777L25DEC/SL ]]><![CDATA[ GENERAL FACTS]]><![CDATA[ 1.SSR FOID AF HK1/PPFR15DC33906]]><![CDATA[ 2.OSI YY VENTA WWW.LAN.COM]]><![CDATA[ 3.SSR OTHS AF LAXP]]><![CDATA[ 4.SSR OTHS AF LAXP]]><![CDATA[ 6.SSR OTHS AF LAXP]]><![CDATA[ 7.OSI LA SC.REAC 0228/31OCT21]]><![CDATA[ 8.SSR OTHS AF LAXP]]><![CDATA[ 9.SSR OTHS AF LAXP]]><![CDATA[ REMARKS]]><![CDATA[ 1.H-ID VENTA WWW.1646474003]]><![CDATA[ 2.H-LANCOM PAYMENT ATTEMPT]]><![CDATA[ 4.H-PLS CHK POSS DUPE OR LAN WILL CNL AFTER 12 HRS]]><![CDATA[ 5.H-PLS ADV TKT NBR BEFORE 31OCT21 1256 UHN LT OR AUTO CNL]]><![CDATA[ 6.H-SERVICE FEE EUR0.00/P1]]><![CDATA[ 7.H-IDVENTAPAGO WWW.1646474983]]><![CDATA[ 8.PNR WORKED ARU]]><![CDATA[ 9.NO ACTIONABLE TICKETS]]><![CDATA[ 10.NO ACTIONABLE TICKETS]]><![CDATA[ OAC - LA UHN LW 2049849 ]]><![CDATA[ UHN-UHN-LW.UHN5SHT 0656/28OCT21 CZMWQP H]]></Response> </SabreCommandLLSRS></soap-env:Body></soap-env:Envelope>`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions