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
No Match

r"
"
igm

Test String

Code Generator

Generated Code

const regex = new RegExp('(([a-z]*[.:]*)\\s*((\\d*[.]\\d*)+$))', 'igm') const str = `"LOWE’S HOME CENTERS, INC. 5770 READ BOULEUARD NEW ORLEANS, LA 70127 (504) 613-1800 - SALE - SALES 4: S2690BC1 1295021 07-17-10 296458 COMM SERIES QUANTUM 3 BUR 149.00 SUBTOTAL: 149.00 TAX: 13.41 INUOICE 18327 TOTAL: 162.41 MERCH/GIFT CARDS : 162.41 MERCH/GIFT CARD 7334 AUTHCODE 005450 BEGIN BAL TRANSACTION AMT ENDING BAL 216.91 162.41 54.50 STORE: 2690 TERMINAL: 18 07/17/10 09:13:09 OF ITEMS PURCHASED: 1" Grocery_receipts_001.docx.txt,"Walmart x'c Save money. Live better. • (813) 932-0562 Manager COLLEEN BRICKEY 8885 N FLORIDA AVE TAMPA FL 33604 ST# 5221 OP# 00001061 TE# 06 TR# 05332 BREAD 007225003712 F 2.88 N BREAD 007225003712 F 2.88 N GV PNT BUTTR 007874237003 F 3.84 N GV PNT BUTTR 007874237003 F 3.84 N GV PNT BUTTR 007874237003 F 3.84 N GV PNT BUTTR 007874237003 F 3.84 N GV PARM 160Z 007874201510 F 4.98 0 GV CHNK CHKN 007874206784 F 1.98 N GV CHNK CHKN 007874206784 F 1.98 N 12 CT NITRIL 073191913822 2.78 X FOLGERS 002550000377 F 10.48 N SC TUIST UP 007874222682 F 0.84 X EGGS 060538871459 F 1.88 0 SUBTOTAL 46.04 TAX 1 7.000 X 0.26 TOTAL 46.30 DEBIT TEND 46.30 CHANGE DUE 0.00 EFT DEBIT PAY FROM PRIMARY ACCOUNT : 5259 1. TOTAL PURCHASE PAYMENT DECLINED DEBIT NOT AVAILABLE 11/06/11 02:21:54 EFT DEBIT PAY FROM PRIMARY ACCOUNT : 5259 1. TOTAL PURCHASE REF # 131000195280 NETWORK ID. 0071 APPR CODE 297664 11/06/11 02:22:54 ft ITEMS SOLD 13 TC# 0432 2121 1542 2401 9590 Lagawag Is back for Electronics, Togs, and Jewelrg. 10/17/11-12/16/11 11/06/11 02:22:59" traderjoes-receipt1.docx.txt,"TRADER JOE’S “V. \\L3P 2-49 T 0.10 T OPEN 8:00AM TO 10:00PM DAILY * LOWFAT 1% MILK - HALF GALLON ^GROCERY NON TAXABLE 1. 6 0.59 ^GROCERY NON TAXABLE 2. 10.19 GROCERY NON TAXABLE ^ MISSISSIPPI MUD 32 OZ CROCK * CRY “• TJ!S VEGGIE STIX £ BAGEL MINI WHEAT 4 PK * CHICKEN CH2 YMEIN STIR FRY MIX * PIZZA ORGANIC SICILIA?? STYLE R « TJ'S CHEESE & GARLIC CROUTONS * LA GRANJA SYRAH LES CAVES JOSEPH BORDEAUX * CHICKEN ORANGE MANDARIN W/SCE * DARK CHOCOLATE ROCKY ROAD SQUA * RESTAURANT-STYLE WHITE CHIPS ~ SLICED TURKEY ROASTED o CRACKERS MULTIGRAIN ^ SALSA CHIPOTLE HOT -FRESH PK BOYSENBERRY PRESERVES * CHUNKY SALTED PEANUT BUTTER * TJ SLICED JACK W/PEPPERS «* SORRENTO SALAD TJ'S * CHOC BAR FLD'DRKSPEC « CHOC BAR FLD DRKSPEC \$66.87 \$0.91 \$67.78 \$67.78 SUBTOTAL STATE TAX 1 TOTAL DEBIT PURCHASE SWIPED AUTH# 402241 INVOICE #: 5876 ,199,,00, 02-09-2012 06:45PM REFERENCE #: 293536 ITEMS 33 S, Christian 02-09-2012 06:43PM 0199 04 0098 5876 THANK YOU FOR SHOPPING AT TRADER JOE'S www.traderjoes.com" transaction-1.docx.txt,"The Pharmacy America Trusts • Since 1901"" I'm MARILYN. Thank you for allowing me to serve you today, 502 10 9032 05988 027 RFN# 0598-8279-0320-1003-2820 F SMPLY SLN ALL4.25Z 1A 7.00 SALE F DULC0LAX 8.30Z 1A 10.00 SALE DOVE TRTMN M0IST8Z 1A 4.00 SALE MFG COUPON 1 1.50-MFGC MFG COUPON 1 4.00-MFGC MFG COUPON 1 5.00-MFGC SUBTOTAL 10.50 A-6.85% SALES TAX TOTAL CASH 12.00 CHANGE .06 HAG ADVERTISED SAVINGS: 7.97 MFG COUPON SAVINGS: 10.50 YOUR TOTAL SAVINGS: 18.47 `; // 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