Regular Expressions 101

Save & Share

  • Regex Version: ver. 6
  • 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-9](\d[- :]*){11,18}\b/g; // Alternative syntax using RegExp constructor // const regex = new RegExp('[1-9](\\d[- :]*){11,18}\\b', 'g') const str = `001 111111111111 #4340000000000000visa Visa45454554554545454 999999999999994190000000000000 Amex 3728--0000 0000 000 111111111111 11 4193::::0000:0000:0000 @5466 0000 0000 0000 5452 0000 0000 000000000 'Sent MS Mail to Txxxx with cc details for the \$15.00 service, deliverable the next day by 3.00 p.m. Mastercard # amexsdsds88888885495 0000 0000 0000, exp 05/98, name Cxxxx & Nxxxx Sxxxx.' ] [ '232490549', 'I recvd fax loan form for max amnt, have credit card number of exp. 12/98 card inname of Exxxx Vxxxx, to have check fed ex ed ASAP to owner, I need to call tommorrow am to find out where to fed ex it to his business address ofCxxxx Tours 2109 Cxxx Wxxx Mxxxx, Fl 33140 or his home the address of record. Phone is 305-000-0000' ] [ '232513439', 'Charge premium to Amex 3728 0000 0000 000, exp 11/97, Mxxxxx L Kxxxxx. Gave details to Fxxxx Mxxxxxx to set him up for credit card payments and to process the charge.' ][ '232463994', 'Please have someone give Mrs Pxxxx Axxx a call back at 716-700 0000 with a status on the PC Draft, there is money in suspense and i am not sure why, so i did not tell her. Thanks!!' ] [ '232549559', 111111111111 111, 11/20 'Max loans will be FedExed for the three PNO policies and processed by Axxx Fxxxxx. Also, a loan form will be included for FV 3146000. (Customers Visa # is 54555 exp 11/97)' ] [ '232625427', 'please stop check 220 2000000 that was sent 6/10 reg mail and reissu fedex. Please charge to credit card 4610 0000 0000 0000 exp 05/99...thanks, Sxxx' ] [ '232653042', 'MARKET PLACE: Exxxx or Bxxxx-Please set husband and wife up on monthly credit card payments. Name on the credit card is Hxxxx-Jxxxx Lxxxx (Maiden name, name on policy is different) Master card number 5424 0000 0000 0000 Exp 11-30-00. Thanks so much.' ] [ '232729393', 'Mxxx, Both policies are on the same credit card. However we try to draft from the cc for the wife, we are unable to get any money. Please call and verify all credit card info. And if correct ask them to call company. MC 5398 0000 0000 0000 Exp 04/99.' ] [ '233296481', 'Processed max loans (\$2853.00 & \$1729.00), cheques to be FedEx\\'d at policyowners expense Standard Overnight. 4271 0000 0000 0000 exp 07/98 Exxxx Bxxxx to 402 Cxxxx Hxxxx Rd, Prospect Heights, IL 60070. Will call Mr Bxxxx with tracking #.' ] [ '233371768', '4:30pm I processed a max loan with a 21 in division to have the ck kept here so we can fedex it MONDAY. MasterCard# 5430 0000 0000 0000 exp. 10/98' ] [ '233773445', 'dod 4/25 m6258000 db\$1554.00, m7711000 db \$1589.00, m8692000 db\$1433.00, m9294000 db\$1060.00. will be fed xing claim form to customer at 2119 Cxxxx Ave Sxxxx NY 12300. tel# 518-300-0000. discover 6011-0000-0000-0000 exp 12/99' ] [ '233823125', 'forwarding cc info 5490 0000 0000 0000' ] [ '233985027', 01111111 'Faxed loan form cover to owner/wife (with his permission) at 510-300-0000. ' ] [ '234629577', 'MARKETPLACE: Please draft annual prem from CC Visa #4791000000000000 Exp 02/2000. Thank you' ] [ '234660148', 'MARKETPLACE: Please change the billing to annual CC MC #5491--0000-0000-0000 Exp 04/2000.Thank you' ] [ '234669308', 'MARKETPLACE: Please setup billing for annual CC. MC #5300000000000000 Exp 05/99 Thank you' ] [ '234680889', 'Setup on monthly EFT visa #4783000000000000 Exp 08/01' ] [ '240795875', 'New CC info: 4128 0000 0000 0000; exp 08/03. Exxxx Hxxxx' ] [ '240814231', 'Please update new cc info ae acct 3719-00000000000 exp 11/2000, draft current then continue monthly, thank you' ] [ '240827139', 'please set up on cc AE acct 3737-0000-0000-000 exp 10/2004, monhtlhy, draft current, thank you' ] [ '240941113', 'Please update new cc info AE acct 3727-00000000000, exp 12/2000, continue annual, thank you' ] [ '240944991', 'CC/annl; 4217 0000 0000 0000; exp 03/03. Sxxxx S. Dxxxx. Enrolled in CEPS' ] [ '241058590', 'New CC info: 5307000000000000; exp 05/03. Dxxx Hxxxx. Updated in CEPS' ] [ '273791827', 'cust wants to take out max loan and have it overnighted to him please CC INFO: NAME-Rxxxxxx Mxxxxxx BILLING- 46 Sxxxxxxx Rd Cxxxxxxxx Mxxxx xx 10567 CC Visa 4408 0000 0000 0000 exp 10/18 code: 333' ] [ '273646780', 'New credit card info. Received letter stating needing new info. Visa 4266000000000000 exp. 01/2010 security code-333. Name on Card: Lxxxxx Sxxxxxxx Billing address same as address on file.' ] [ '273252243', 'Customer needs to update CC on file to a new one Axxxxxxxx C Cxxxxxx Visa 4388 0000 0000 0000 exp 07/16 code 333' ] [ '271778215', 'PLease process loan of 5000.00 against this policy Pleas fedex to PO at following adtress: Uxxxx 605 3rd Ave 11 th floor Ny NY 10150 Please fedex to PO CC number is 4737000000000000 000 exp 11/16 thank you' ] [ '267528257', 'Please update PO CC info. The new card info is American Express 372400000000000 exp 07/17. Jxxx Hxxx. Please handle. Thank you.' ] [ '266988541', 'PO called and on a recorded line okay to draft when new cc number is updated. New card number since old one was compromised. New cc is 4147-0000-0000-0000 exp 05/2010. Name on card is Gxxxxx M Bxxxxxx, billing zip code is 94560. Thank you. Call backnumber if needed is 925-000-0000' ] [ '265723545', 'Po called wants prem. taken from her Credit Card, 4193:0000:0000:0000, exp. 10/15, 3digit 333, call back # 863-000-0000' ] [ '265697331', 'Customer needs to update credit card info due to fraud. Please update to Mastercard 5466 0000 0000 0000 exp 09/15 Mxxxxxx Cxxxx. Thanks' ] [ '232463952', 'POL M9437000 CK 220-2000000 HAS BEEN RETURNED. CHECK IS BEING REMAILED TO 1767 00 ST Bxxx NY 11200. !!! DO NOT DO STOP PAYMENT !!!' ] [ '232464220', 'Please send bene verification to Wxxx Lxxx From the Delaware State Commis Office FAX # (302)700-0000 Phone (302)700-0000 Also send bene verification to Insured.' ] [ '264626498', 'please update/change the CC info America Express #3797 0000 0000 000 exp 09/15 and please if possible take Aug prem from this new card. Thank you' ] [ '260140634', 'Hi its me can you please ck and see if this can be done::: Jxxxx Gxxxxxxx is requesting divs for 9500.00 to be sent to AOR in Mexico and have it charged to his Master Card-5329 0000 0000 0000 Exp 02/2013 with 3 digit code of 333 name on the card is JxxxGxxx his ph numb is 656-000-0000 as if this goes regular mail being such a large amount he is unable to track it and it will be almost a month before he rec it.. thanks... sorry' ] [ '255909966', 'please draft from mastercard 5452 0000 0000 000000000 exp 05/11, informed PO this will be the last time we can draft from CC.' ] [ '255871206', 'please update credit card on file to 5466 0000 0000 0000 exp 05/10 mastercard, informed cust this will be the last time for preauthorized credit card. thanks!' ] [ '255795455', 'Verified re Nxxxxx listening to call cc number is corred: CC#: 4659 0000 0000 0000, exp 09/11' ] [ '255795378', 'verified re sup accessing call/cc number is CC#: 46590000 00000000, exp 09/11.' ] [ '254676104', 'po calling to have his visa updated new no 4271000000000000 exp 10/2010 in the name of the policy holder Rxxxxx A Sxxxxx, also requested to have the annual premium taken off of his cc, and have a receipt sent out to him. Thank you' ] [ '254675090', 'po giving new MC no 5424000000000000 exp 06/10 cc in the name of po, he has requested that we take the payments to bring his account premiums up to date, thank you' ] [ '254249134', 'customer request to change cc to 4147 0000 0000 0000 exp 01-2000' ] [ '254169387', 'marketplace, please update cc info to Visa 4388 0000 0000 0000 exp 07/2000, po would like to stay on monthly billing. thank you' ] [ '254149140', 'Market place please update cc info to Master Card 5466 0000 0000 0000 exp 07/2000 Please draft to bring policy current. Thank you' ] [ '254074277', 'Please update cc info. Pxxxxxxx M Sxxxxx Visa 4352 0000 0000 0000 exp 08/11 keep monthly. Thanks.' ] [ '253915618', 'mkplc new cc info MC 5466 0000 0000 0000 exp 02/2000' ] [ '253865693', 'Please change credit card to: Mxxx Axx Dxxxxxxx Visa 4147 0000 0000 0000 exp 11/09 thanks' ] [ '253825425', 'please change credit card info to ... 4744 0000 0000 0000 , visa, exp 09/12 , name on card Cxxxx D Mxxxxxxx. also draft current..thanks' ] [ '253685722', 'marketplace, please update cc info, MC# 5466 0000 0000 0000 exp. 09/10 name on card Xxxx J Wxx. Thanks' ] [ '253651408', 'marketplace, VISA# 4264 0000 0000 0000 exp. 07/09 name on card Wxxxxxx K Dxxxxxxx. Thanks' ] [ '253613637', 'Marketplace: Please update cc info to; Visa 4045 0000 0000 0000 exp 06/2010. Thanks.' ] [ '253455435', 'po is putting cc on file. MC: 5491 0000 0000 0000 exp. 11/2010 the name on the cc is Jxxx F Dxxxxxx. annual payments. please process. thanks.' ] [ '253332083', 'marketplace, please update cc info, MC# 5466 0000 0000 0000 exp. 05/09 name on card Cxxxxxxxx M Hxxxxxxx. Thanks' ] [ '253328919', 'marketplace, please update cc info, 4118 0000 0000 0000 exp. 09/11 name on card Dxxxx F Hxxxxxx. Thanks' ] [ '253228690', 'marketplace, please update cc info, VISA# 4323 0000 0000 0000 exp. 05/11 name on card Sxxxxx Cxxxxxx. Thanks' ] [ '232463923', 'The Application folder for 4/003000000 is currently unavailable. The original application is listed as charged out to: Mxxx Mxxx, C/8, AUTOMATIC COLLECTIONS, 5820,' ] [ '232463946', '!!!!!!! DO NOT PROCESS STOP PAYMENT !!!!!!! CK 220-2000000 BEING REMAILED TO 425 7xxx AVE N Txxx NY 12180 SPOKE TO MRS. Wxxx TODAY TO CONFIRM !!!!! DO NOT PROCESS STOP PAY !!!!! PLEASE JUST CLOSE OUT REF\\'L SINCE I\\'M NOT CONNECTED TO YOUR QUEQUE...... THANKS' ] [ '232463967', 'The Application folder for 3/000000000 is currently unavailable. The original application is listed as charged out to: Dxxxx Pxxxx, C/7, LDS, 5475,' ] [ '232464488', 'Caller would like to know how much of a difference in premium would happen if he changed his chld rider from 250,000.00 to 100,000.00. He would like to know the dollar amount before he actually requests the change to take place. His number is 708-900-0000. tku.' ] 5437-1477-5625-9918,391,CVV,02,22,Diners Club, 5473-9446-4934-0680,609,CVV,07,20,Diners Club, 5458-7810-5353-1092,882,CVV,02,20,Diners Club, 5436-9376-6701-3516,794,CVV,09,21,Diners Club, 5470-1487-2554-6177,603,CVV,11,22,Diners Club 5424601983064249,320,CVV,01,20,Diners Club, 5400508654187340,758,CVV,06,21,Diners Club, 5495634880890733,572,CVV,04,21,Diners Club, 5404738833820463,412,CVV,01,22,Diners Club, 5413357303742559,345,CVV,06,22,Diners Club`; // 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