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

import Foundation let pattern = ##"(?P<claim_number>\d{10,50})(\s+)(?P<ID>\d{1,10})(\s+)(?P<feature_type>[a-z-]{2,50})?(\s+)(?P<loss_location>(\w[.'\s#\/;@`&\w,%\-]*)+)?(?P<state>[a-zA-Z]{2,5})?(\s+)(?P<status>[a-zA-Z]{1})?(\s+)[$]?(?P<feature_reserve>[+-]?(\d*(,\d+)*(.)(\d+)))?(\s+)[$]?(?P<feature_paid>[+-]?(\d*(,\d+)*(.)(\d+)))?(\s+)[$]?(?P<alae_reserve>[+-]?(\d*(,\d+)*(.)(\d+)))?(\s+)[$]?(?P<alae_paid>[+-]?(\d*(,\d+)*(.)(\d+)))?(\s+)"## let regex = try! NSRegularExpression(pattern: pattern, options: [.anchorsMatchLines, .caseInsensitive]) let testString = #""" Loss Run Report KUHNLE BROTHERS, INC. Evaluation Date: 6/7/2018 Company: 01 NATIONAL INTERSTATE INS CO Account Number: 4000010531 Broker: NATIONAL RISK MANAGEMENT SERV. Date of Loss Report Date File Number ID Type Location of Loss ST Status Claimant Driver Facts of Loss Loss Reserve Loss Paid Exp Reserve Exp Paid Total Incurred Start: Policy Number: CAT001053100 Policy Term: 9/1/2012 to 9/1/2013 Auto Liability 11/20/2012 12/12/2012 000001123777 3 PD AUBURN RD - CONCORD TOWNSHIP, OH OH C 0.00 2,102.24 0.00 85.00 2,187.24 FRIEDRICH, PAMELA ADAM FREDERICK IV HIT OV OCCURRENCE: 2/14/2013 2/15/2013 000001129136 1 PD I-77 - BECKLEY, WV WV C 0.00 0.00 0.00 0.00 0.00 KUHNLE BROTHERS, INC. 14905 CROSS CREEK PARKWAY U U IV ROLLED OCCURRENCE: WEST VIRGINIA PARKWAY AUTH 3310 PIEDMONT ROAD U U IV ROLLED OCCURRENCE: 2/14/2013 2/15/2013 000001129136 3 PD I-77 - BECKLEY, WV WV C 0.00 1,410.00 0.00 0.00 1,410.00 EMERGENCY RESPONSE & TRAIN PO BOX 72333 U U IV ROLLED OCCURRENCE: 2/14/2013 2/15/2013 000001129136 4 PD I-77 - BECKLEY, WV WV C 0.00 7,001.22 0.00 0.00 7,001.22 EVERGREEN ENVIRONMENTAL PO BOX 1051 U U IV ROLLED OCCURRENCE: 6/10/2013 6/19/2013 000001140425 3 PD U - U, NY NY C 0.00 0.00 0.00 0.00 0.00 BOWERS, ALLISON JAMES COX IV & OV COLLIDED OCCURRENCE: 6/10/2013 6/19/2013 000001140425 4 BI U - U, NY NY C 0.00 0.00 0.00 1,100.08 1,100.08 VOVK, SERGEY A JAMES COX IV & OV COLLIDED OCCURRENCE: 7/12/2013 7/23/2013 000001143316 3 PD OHIO TURNPIKE @ EXIT 142 - U, OH OH C 0.00 6,737.49 0.00 14,876.35 21,613.84 SNIDER, MICHAEL JOHN MORRISON WORD VS WORD OCCURRENCE: 7/19/2013 8/23/2013 000001145903 4 PD HWY 75 NB - CINCINNATI, OH OH C 0.00 0.00 0.00 0.00 0.00 DAVIS, DENISE JOHN MARTIN INSURED REARENDED CLAIMANT OCCURRENCE: Subtotal 0.00 22,885.16 0.00 16,061.43 38,946.59 Page 1 of 7 Confidential - Property of National Interstate 6/8/2018 Loss Run Report KUHNLE BROTHERS, INC. Evaluation Date: 6/7/2018 Company: 01 NATIONAL INTERSTATE INS CO Account Number: 4000010531 Broker: NATIONAL RISK MANAGEMENT SERV. Date of Loss Report Date File Number ID Type Location of Loss ST Status Claimant Driver Facts of Loss Loss Reserve Loss Paid Exp Reserve Exp Paid Total Incurred Auto Physical Damage 2/14/2013 2/15/2013 000001129136 1 COLL I-77 - BECKLEY, WV WV C 0.00 0.00 0.00 0.00 0.00 KUHNLE BROTHERS, INC. 14905 CROSS CREEK PARKWAY U U IV ROLLED OCCURRENCE: 6/10/2013 6/19/2013 000001140425 1 COLL U - U, NY NY C 0.00 0.00 0.00 0.00 0.00 KUHNLE BROTHERS, INC. 14905 CROSS CREEK PARKWAY JAMES COX IV & OV COLLIDED OCCURRENCE: 7/19/2013 8/23/2013 000001145903 1 COLL HWY 75 NB - CINCINNATI, OH OH C 0.00 0.00 0.00 0.00 0.00 KUHNLE BROTHERS, INC. 14905 CROSS CREEK PARKWAY JOHN MARTIN INSURED REARENDED CLAIMANT OCCURRENCE: Subtotal 0.00 0.00 0.00 0.00 0.00 End: Policy Number: CAT001053100 Policy Term: 9/1/2012 to 9/1/2013 0.00 22,885.16 0.00 16,061.43 38,946.59 Start: Policy Number: EXT001053100 Policy Term: 9/1/2012 to 9/1/2013 000000000000 0 NOTHING TO REPORT 0.00 0.00 0.00 0.00 0.00 OCCURRENCE: Subtotal 0.00 0.00 0.00 0.00 0.00 End: Policy Number: EXT001053100 Policy Term: 9/1/2012 to 9/1/2013 0.00 0.00 0.00 0.00 0.00 Start: Policy Number: GLT001053100 Policy Term: 9/1/2012 to 9/1/2013 000000000000 0 NOTHING TO REPORT 0.00 0.00 0.00 0.00 0.00 OCCURRENCE: Subtotal 0.00 0.00 0.00 0.00 0.00 End: Policy Number: GLT001053100 Policy Term: 9/1/2012 to 9/1/2013 0.00 0.00 0.00 0.00 0.00 Start: Policy Number: CAT001053101 Policy Term: 9/1/2013 to 9/1/2014 Page 2 of 7 Confidential - Property of National Interstate 6/8/2018 Loss Run Report KUHNLE BROTHERS, INC. Evaluation Date: 6/7/2018 Company: 01 NATIONAL INTERSTATE INS CO Account Number: 4000010531 Broker: NATIONAL RISK MANAGEMENT SERV. Date of Loss Report Date File Number ID Type Location of Loss ST Status Claimant Driver Facts of Loss Loss Reserve Loss Paid Exp Reserve Exp Paid Total Incurred Auto Liability 9/5/2013 11/18/2014 000001186210 3 PD RT 81 S/B @ MM 55.2 - U, VA VA C 0.00 0.00 0.00 0.00 0.00 JOVIC, MILOS MARK MILLER TIRE BLOWOUT OCCURRENCE: 10/25/2013 10/25/2013 000001151696 3 PD S/B RT 83 - HARRISBURG, PA PA C 0.00 0.00 0.00 0.00 0.00 U U CLIFF KUDLACK INSURED VEHICLE HIT OBJECT OCCURRENCE: 10/28/2013 10/28/2013 000001151900 2 BI RT 306 AND BELL ST6 - SOUTH RUSSELL, OH OH C 0.00 135,000.00 0.00 0.00 135,000.00 MILLER, MARIELLEN EDWARD KRASOUSKY IV HIT OV OCCURRENCE: 10/28/2013 10/28/2013 000001151900 2 PD RT 306 AND BELL ST6 - SOUTH RUSSELL, OH OH C 0.00 10,406.87 0.00 0.00 10,406.87 MILLER, MARIELLEN EDWARD KRASOUSKY IV HIT OV OCCURRENCE: 11/13/2013 11/18/2013 000001153640 3 PD RTE 45 & LINCOLN - SALEM, OH OH C 0.00 0.00 0.00 0.00 0.00 BUTLER REFRIGERATED MEATS JOHN BOROS RECORD ONLY OCCURRENCE: 11/21/2013 11/21/2013 000001154099 3 PD SPRU PARKING LOT - NISKAYUNA, NY NY C 0.00 1,817.16 0.00 0.00 1,817.16 BONCELLA, JOHN TAMMY ZIMMERMAN IV HIT OV PARK VEH OCCURRENCE: 11/26/2013 12/6/2013 000001155289 1 MEDPIP US 301 S/B - MASSEY, MD MD C 0.00 0.00 0.00 0.00 0.00 HARDIMAN, LEE LEE HARDIMAN CLAIMANT REAR-ENDED INSURED OCCURRENCE: 000001155234 5/12/2014 5/13/2014 000001169287 3 PD AUBURN RD/RT 322 OH C 0.00 9,375.72 0.00 85.00 9,460.72 SHAKER, SUE JOHN KONKOL RECORD ONLY OCCURRENCE: 5/29/2014 10/9/2014 000001182641 3 PD PILOT TS/5820 HAGMAN RD - TOLEDO, OH OH C 0.00 11,509.17 0.00 277.25 11,786.42 PILOT TRAVEL CENTERS LLC 5508 LONAS RD JEFF BORKOWSKI INSURED VEHICLE HIT OBJECT OCCURRENCE: Page 3 of 7 Confidential - Property of National Interstate 6/8/2018 Loss Run Report KUHNLE BROTHERS, INC. Evaluation Date: 6/7/2018 Company: 01 NATIONAL INTERSTATE INS CO Account Number: 4000010531 Broker: NATIONAL RISK MANAGEMENT SERV. Date of Loss Report Date File Number ID Type Location of Loss ST Status Claimant Driver Facts of Loss Loss Reserve Loss Paid Exp Reserve Exp Paid Total Incurred 6/20/2014 3/4/2015 000001195524 3 PD 15 ALLEN ST - MYSTIC, CT CT C 0.00 0.00 0.00 0.00 0.00 BULK CONNECTION INC 15 ALLEN STREET U U PROPERTY DAMAGE OCCURRENCE: 8/7/2014 8/8/2014 000001176918 1 PD I-80 AT MM 146 REST STOP - FREEMONT, IN IN C 0.00 0.00 0.00 0.00 0.00 KUHNLE BROTHERS, INC. 14905 CROSS CREEK PARKWAY JOHN KONKOL RECORD ONLY OCCURRENCE: Subtotal 0.00 168,108.92 0.00 362.25 168,471.17 Auto Physical Damage 11/26/2013 12/6/2013 000001155234 1 COLL US 301 S/B - MASSEY, MD MD C 0.00 0.00 0.00 569.25 569.25 KUHNLE BROTHERS, INC. 14905 CROSS CREEK PARKWAY LEE HARDIMAN CLAIMANT REAR-ENDED INSURED OCCURRENCE: 000001155234 Subtotal 0.00 0.00 0.00 569.25 569.25 End: Policy Number: CAT001053101 Policy Term: 9/1/2013 to 9/1/2014 0.00 168,108.92 0.00 931.50 169,040.42 Start: Policy Number: EXT001053101 Policy Term: 9/1/2013 to 9/1/2014 000000000000 0 NOTHING TO REPORT 0.00 0.00 0.00 0.00 0.00 OCCURRENCE: Subtotal 0.00 0.00 0.00 0.00 0.00 End: Policy Number: EXT001053101 Policy Term: 9/1/2013 to 9/1/2014 0.00 0.00 0.00 0.00 0.00 Start: Policy Number: GLT001053101 Policy Term: 9/1/2013 to 9/1/2014 000000000000 0 NOTHING TO REPORT 0.00 0.00 0.00 0.00 0.00 OCCURRENCE: Subtotal 0.00 0.00 0.00 0.00 0.00 End: Policy Number: GLT001053101 Policy Term: 9/1/2013 to 9/1/2014 0.00 0.00 0.00 0.00 0.00 Page 4 of 7 Confidential - Property of National Interstate 6/8/2018 Loss Run Report KUHNLE BROTHERS, INC. Evaluation Date: 6/7/2018 Company: 01 NATIONAL INTERSTATE INS CO Account Number: 4000010531 Broker: NATIONAL RISK MANAGEMENT SERV. Date of Loss Report Date File Number ID Type Location of Loss ST Status Claimant Driver Facts of Loss Loss Reserve Loss Paid Exp Reserve Exp Paid Total Incurred Start: Policy Number: CAT001053102 Policy Term: 9/1/2014 to 9/1/2015 Auto Liability 10/22/2014 11/10/2014 000001185441 3 PD CRANE AVENUE BRIDGE - KENT, OH OH C 0.00 0.00 0.00 65.00 65.00 CLEGG, BRIAN DEXTER BRITTNEY PER OVC: IV MADE TURN HIT OV OCCURRENCE: 1/6/2015 1/7/2015 000001190070 3 PD ROUTE 70 E/B - BEDFORD, PA PA C 0.00 6,121.84 0.00 0.00 6,121.84 SUDLER, JUDITH AL CASTERLINE INSURED REARENDED CLAIMANT OCCURRENCE: 1/8/2015 4/24/2015 000001200301 1 PD CT C 0.00 29,722.95 0.00 963.50 30,686.45 NY DEPT OF ENVIRONMENTAL 625 BROADWAY ED KRASOUSKI FERIC SPILLED OUT OCCURRENCE: 1/8/2015 4/24/2015 000001200301 2 PD CT C 0.00 16,004.67 0.00 963.50 16,968.17 CT DEPT. OF ENERGY & 79 ELM STREET ED KRASOUSKI FERIC SPILLED OUT OCCURRENCE: 1/20/2015 1/20/2015 000001191090 3 PD JOHNSTON & SEVILLE - CLEVELAND, OH OH C 0.00 973.62 0.00 0.00 973.62 GREATER CLEVELAND RTA 1240 W 6TH ST JONATHON STOCKDALE IV AND OV COLLIDED OCCURRENCE: 1/20/2015 1/20/2015 000001191090 4 BI JOHNSTON & SEVILLE - CLEVELAND, OH OH C 0.00 250.00 0.00 0.00 250.00 SLEDGE, TYRA JONATHON STOCKDALE IV AND OV COLLIDED OCCURRENCE: 1/20/2015 1/26/2015 000001191565 3 PD STATE ROUTE 57 - ELYRIA, OH OH C 0.00 0.00 0.00 0.00 0.00 U-HAUL INCORPORATED JAMES CASTERLINE RECORD ONLY OCCURRENCE: 1/20/2015 1/26/2015 000001191565 4 BI STATE ROUTE 57 - ELYRIA, OH OH C 0.00 20,000.00 0.00 0.00 20,000.00 BEAVERS, JAYSON JAMES CASTERLINE RECORD ONLY OCCURRENCE: 1/20/2015 1/26/2015 000001191565 5 BI STATE ROUTE 57 - ELYRIA, OH OH C 0.00 8,500.00 0.00 0.00 8,500.00 WORLEY, DANIEL JAMES CASTERLINE RECORD ONLY OCCURRENCE: Page 5 of 7 Confidential - Property of National Interstate 6/8/2018 Loss Run Report KUHNLE BROTHERS, INC. Evaluation Date: 6/7/2018 Company: 01 NATIONAL INTERSTATE INS CO Account Number: 4000010531 Broker: NATIONAL RISK MANAGEMENT SERV. Date of Loss Report Date File Number ID Type Location of Loss ST Status Claimant Driver Facts of Loss Loss Reserve Loss Paid Exp Reserve Exp Paid Total Incurred 3/3/2015 3/9/2015 000001195919 3 PD W. 14TH ST & STEELYARD - CLEVELAND, OH OH C 0.00 6,520.66 0.00 0.00 6,520.66 MONROE, BRENDA JOHN MANFREDI RECORD ONLY OCCURRENCE: 3/3/2015 3/9/2015 000001195919 4 BI W. 14TH ST & STEELYARD - CLEVELAND, OH OH C 0.00 7,500.00 0.00 0.50 7,500.50 MONROE, BRENDA K JOHN MANFREDI RECORD ONLY OCCURRENCE: 4/12/2015 4/13/2015 000001199069 4 PD I-35 - HILLSBORO, TX TX C 0.00 0.00 0.00 0.00 0.00 U, U U GLENN LONG RECORD ONLY OCCURRENCE: 5/20/2015 5/20/2015 000001202722 3 PD RT 42 - HIGHLAND PARK, IL IL C 0.00 1,462.53 0.00 0.00 1,462.53 RENTAL CAR, ENTERPRISE DANNY SAMMONS RECORD ONLY OCCURRENCE: 6/2/2015 6/3/2015 000001203989 3 PD FERRY & LEXINGTON - NEWARK, NJ NJ C 0.00 1,989.02 0.00 132.93 2,121.95 RIVERA, LUIS CHRIS LICKLY OV & IV COLLIDED OCCURRENCE: 6/9/2015 6/10/2015 000001204641 2 PD RT 495 - OYSTER BAY, NY NY C 0.00 0.00 0.00 0.00 0.00 HIRSHON, STEVEN ED KRASOUSKY RECORD ONLY OCCURRENCE: Subtotal 0.00 99,045.29 0.00 2,125.43 101,170.72 Auto Physical Damage 7/23/2015 11/9/2015 000001217916 1 OTHER OH C 0.00 0.00 0.00 700.00 700.00 KUHNLE BROTHERS, INC. 14905 CROSS CREEK PKWY IVS DAMAGED OCCURRENCE: Subtotal 0.00 0.00 0.00 700.00 700.00 End: Policy Number: CAT001053102 Policy Term: 9/1/2014 to 9/1/2015 0.00 99,045.29 0.00 2,825.43 101,870.72 Start: Policy Number: EXT001053102 Policy Term: 9/1/2014 to 9/1/2015 000000000000 0 NOTHING TO REPORT 0.00 0.00 0.00 0.00 0.00 OCCURRENCE: Page 6 of 7 Confidential - Property of National Interstate 6/8/2018 Loss Run Report KUHNLE BROTHERS, INC. Evaluation Date: 6/7/2018 Company: 01 NATIONAL INTERSTATE INS CO Account Number: 4000010531 Broker: NATIONAL RISK MANAGEMENT SERV. Date of Loss Report Date File Number ID Type Location of Loss ST Status Claimant Driver Facts of Loss Loss Reserve Loss Paid Exp Reserve Exp Paid Total Incurred Subtotal 0.00 0.00 0.00 0.00 0.00 End: Policy Number: EXT001053102 Policy Term: 9/1/2014 to 9/1/2015 0.00 0.00 0.00 0.00 0.00 Start: Policy Number: GLT001053102 Policy Term: 9/1/2014 to 9/1/2015 General Liability 2/2/2015 6/11/2015 000001204812 1 PD UPS FACILITY - LONDONDERRY, NH NH C 0.00 17,725.76 0.00 0.00 17,725.76 CRYOTECH 6103 ORTHOWAY CRAIG FLINCHUN PRODUCT NOT DELIVERED OCCURRENCE: Subtotal 0.00 17,725.76 0.00 0.00 17,725.76 End: Policy Number: GLT001053102 Policy Term: 9/1/2014 to 9/1/2015 0.00 17,725.76 0.00 0.00 17,725.76 Start: Policy Number: EXT001053103 Policy Term: 9/1/2015 to 9/1/2016 000000000000 0 NOTHING TO REPORT 0.00 0.00 0.00 0.00 0.00 OCCURRENCE: Subtotal 0.00 0.00 0.00 0.00 0.00 End: Policy Number: EXT001053103 Policy Term: 9/1/2015 to 9/1/2016 0.00 0.00 0.00 0.00 0.00 Start: Policy Number: EXT001053104 Policy Term: 9/1/2016 to 9/1/2017 000000000000 0 NOTHING TO REPORT 0.00 0.00 0.00 0.00 0.00 OCCURRENCE: Subtotal 0.00 0.00 0.00 0.00 0.00 End: Policy Number: EXT001053104 Policy Term: 9/1/2016 to 9/1/2017 0.00 0.00 0.00 0.00 0.00 4000010531 0.00 307,765.13 0.00 19,818.36 327,583.49 Page 7 of 7 Confidential - Property of National Interstate 6/8/2018 """# let stringRange = NSRange(location: 0, length: testString.utf16.count) let matches = regex.matches(in: testString, range: stringRange) var result: [[String]] = [] for match in matches { var groups: [String] = [] for rangeIndex in 1 ..< match.numberOfRanges { let nsRange = match.range(at: rangeIndex) guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue } let string = (testString as NSString).substring(with: nsRange) groups.append(string) } if !groups.isEmpty { result.append(groups) } } print(result)

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 Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression