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

/
/
gm

Test String

Code Generator

Generated Code

const regex = /(<\ITEM [\s\S]*?\/ITEM\>)/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('(<\\ITEM [\\s\\S]*?\\\/ITEM\\>)', 'gm') const str = `<SBDATA> <SBNRMFR> <SBNBR>31A0179</SBNBR> <MFR>81205</MFR> </SBNRMFR> <MDNRMFR> <MDNBR>BB31A0179</MDNBR> <MFR>81205</MFR> </MDNRMFR> <ICS>SEP 5/16</ICS> </SBDATA> <ITEM CHAPNBR="23" SECTNBR="31" UNITNBR="03" FIGNBR="10B" ITEMNBR="002K" ILLUSIND="0" INDENT="1" ATTACH="0" CHG="U" KEY="K23310310B002K" REVDATE="20200905"> <EFFECT EFFRG="101200"> </EFFECT> <PNRMFR><PNR>413W1310-101B</PNR> <MFR>81205</MFR> </PNRMFR> <UPA>RF</UPA> <TQA>AR</TQA> <ADT>OVERDOOR (PASSENGER ADDRESS SYSTEM ONLY)</ADT> <LBL>&PLD;</LBL> <PLD>SECT. 41 LH</PLD> <LBL>&NH2;</LBL> <REFINT REFID="K25210810B" REFTYPE="NH2">25-21-08-10B</REFINT> </ITEM> <AIPC MODEL="777-200/300" OIDATE="19951005" REVDATE="20200905" TSN="107" DOCNBR="D633W111" CUS="EAD" CHG="R" LANG="EN" CUSNAME="EMIRATES" SPL="81205"><TITLE>AIRCRAFT ILLUSTRATED PARTS CATALOG</TITLE><MFMATR><INTRO CHG="U" KEY="INTRO" REVDATE="20200905"> <TITLE>INTRODUCTION</TITLE> <PARA></PARA> <TITLE>PURPOSE</TITLE> <PARA></PARA><PARA>This document is prepared, issued and revised by Boeing for the exclusive use of its customers and is intended for use in provisioning, requisitioning, storing, and issuing line replaceable aircraft parts and units and in identifying maintenance significant parts. The content of this document is proprietary to Boeing and its customers and is subject to change. The use of any part of this document by any other person or persons for any other purpose without written consent of Boeing is expressly prohibited. In addition, Boeing expressly disclaims any and all responsibility arising from or in any way related to any such use without Boeing's prior written consent thereto. This document is produced to support the configuration of the aircraft at the time of delivery to the original customer and changes submitted by the customer after delivery. It does not necessarily reflect the current configuration of any specific aircraft.</PARA> <PARA></PARA><PARA>The part number content, associated data elements, functional arrangement and breakdown sequence of items contained within this document is produced in accordance with the Air Transport Association (ATA) Specification No. 100. The document requirements in ATA Spec 100 were combined with ATA 2100 to form iSpec 2200 in year 2000. iSpec 2200 defines industry requirements for technical data, digital data transmission, Document Type Definitions (DTD's), and the Common Support Data Dictionary (CSDD) definitions of the data elements.</PARA> <PARA></PARA><PARA>Illustrated Parts Catalog (IPC)/Illustrated Parts Data (IPD) data is available in industry standard, Standard Generalized Markup Language (SGML) in accordance with ATA iSpec 2200. The IPC/IPD is not available in S1000d format.</PARA> <PARA></PARA><PARA>Air Transport Association has been renamed Airlines 4 America (A4A). For additional information or to acquire a copy of any ATA / A4A Specification please contact the following for ordering information:</PARA> <PARA></PARA><PARA>Airlines 4 America (A4A) Phone: 1-202-626-4062 e-mail: pubs@airlines.org Internet Address: www.airlines.org</PARA> <PARA></PARA> <TITLE>GENERAL SYSTEM OF ASSEMBLY ORDER-DETAILED PARTS LIST (DPL)</TITLE> <TXTGRPHC><TXTLINE> </TXTLINE> <TXTLINE>The indenture system used in the Parts Lists of the figures </TXTLINE> <TXTLINE>included within this catalog shows the relationship of one part </TXTLINE> <TXTLINE>to another. For a given item, the number of indentures defines </TXTLINE> <TXTLINE>the relationship of the item to the associated installation, next </TXTLINE> <TXTLINE>higher assembly, or components of the item as follows: </TXTLINE> <TXTLINE> </TXTLINE> <TXTLINE>1234567 </TXTLINE> <TXTLINE>Installation </TXTLINE> <TXTLINE>.Detail Parts for Installation </TXTLINE> <TXTLINE>.Assembly </TXTLINE> <TXTLINE>.Attaching Parts for Assembly </TXTLINE> <ITEM CHAPNBR="25" SECTNBR="85" UNITNBR="00" FIGNBR="10A" ITEMNBR="390K" ILLUSIND="1" INDENT="2" ATTACH="0" CHG="U" KEY="K25850010A390K" REVDATE="20200905"> <EFFECT EFFRG="003100"> </EFFECT> <PNRMFR><PNR>415W0116-237</PNR> <MFR>81205</MFR> </PNRMFR> <UPA>1</UPA> <TQA>AR</TQA> </ITEM> <ITEM CHAPNBR="25" SECTNBR="85" UNITNBR="00" FIGNBR="10A" ITEMNBR="395" ILLUSIND="1" INDENT="2" ATTACH="0" CHG="U" KEY="K25850010A395" REVDATE="20200905"> <EFFECT EFFRG="003100"> </EFFECT> <PNRMFR><PNR>415W0110-241</PNR> <MFR>81205</MFR> </PNRMFR> <UPA>1</UPA> <TQA>AR</TQA> </ITEM>`; // 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