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

/
/
g

Test String

Code Generator

Generated Code

$re = '/(?<=INVOICE).*(?=PO #)/'; $str = '{ "message": "INVOICE Invoice Amount\\r\\n$9,561.60\\r\\n\\r\\nPayment Terms Invoice Date\\r\\nNet 30 Days 12/13/2020\\r\\nInvoice No. Customer No.\\r\\nOSHKOSH DEFENSE, LLC OV 10566540 50062648 5755\\r\\nAttn To: Jason Freese 8/3/2021\\r\\n2307 OREGON STREET\\r\\nOSHKOSH, W I 549032566 PO #: 27040961\\r\\n\\r\\nWeekWorked: 12/13/2020\\r\\n\\r\\nRemit To:\\r\\nTactical Workforce Solutions, Inc. DBA\\r\\nSTS Technical Services\\r\\nP. O. Box 628318 Orlando, FL 32862-\\r\\n8318\\r\\n\\r\\nCustomer Name Department Customer Number Payment Terms\\r\\nOSHKOSH DEFENSE, LLC OSHKOSH CORP - JLTV 5755 Net 30 Days\\r\\n\\r\\nDescription Type Units Rate Amount\\r\\nWeekWorked: 12/13/2020\\r\\n\\r\\nBEHNE, JACK Carroll REG 40.00 $49.80 $1,992.00\\r\\nGill Jr., Gary Len REG 40.00 $49.80 $1,992.00\\r\\nJarrett, Quincy Monroe REG 32.00 $49.80 $1,593.60\\r\\nRivera Sr., Jesus Amado REG 40.00 $49.80 $1,992.00\\r\\nSawyer, Robert Demetrius REG 40.00 $49.80 $1,992.00\\r\\nTotal: $9,561.60\\r\\n\\r\\nREG: 192.00\\r\\nTotal: 192.00\\r\\nTotal - This Invoice:\\r\\n$9,561.60\\r\\n\\r\\nPage 1 of 1 A late charge of 1 1/2% per month will be charged for this invoice that remains unpaid beyond the payment terms.OSHKOSH CORPORATION\\r\\nEmployee Timesheet\\r\\nEmployee: BEHNE, JACK Revision: 1\\r\\nEmployee ID: 282334 Schedule: Weekly\\r\\nClass: Contractor Period Ending: Dec 12, 2020\\r\\nPrinted: Dec 14, 2020 7:52 AM Page: 1 of 1\\r\\nLine Project.Activity Charge Sun Mon Tue Wed Thu Fri Sat Line\\r\\nNo Cost Center Description 12/6 12/7 12/8 12/9 12/10 12/11 12/12 Totals\\r\\nP107016.C922206 JLTV - GIPS CPFF 8.0 8.0 8.0 8.0 8.0 40.0\\r\\n1 50296 Support.USMC OCONUS\\r\\n\\r\\n2\\r\\n\\r\\n3\\r\\n\\r\\n4\\r\\n\\r\\n5\\r\\n\\r\\n6\\r\\n\\r\\n7\\r\\n\\r\\n8\\r\\n\\r\\n9\\r\\n\\r\\n10\\r\\n\\r\\n11\\r\\n\\r\\n12\\r\\n\\r\\n13\\r\\n\\r\\n14\\r\\n\\r\\n15\\r\\nTotal Regular Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\nTotal Overtime Hours:\\r\\nTotal Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\n\\r\\nSignature: BEHNE, JACK (282334) By signing this timesheet you are certifying that hours were incurred on the project Approval: MCCARTHY, CHARLES W. (156593)\\r\\nDate: Dec 11, 2020 11:25:21 PM and day specified. Intentionally mischarging your time can subject you to Date: Dec 14, 2020 7:52:10 AM\\r\\ndisciplinary action as well as civil or criminal penalities.OSHKOSH CORPORATION\\r\\nEmployee Timesheet\\r\\nEmployee: GILL JR., GARY L. Revision: 1\\r\\nEmployee ID: 165924 Schedule: Weekly\\r\\nClass: Contractor Period Ending: Dec 12, 2020\\r\\nPrinted: Dec 14, 2020 7:52 AM Page: 1 of 1\\r\\nLine Project.Activity Charge Sun Mon Tue Wed Thu Fri Sat Line\\r\\nNo Cost Center Description 12/6 12/7 12/8 12/9 12/10 12/11 12/12 Totals\\r\\nP107016.C922206 JLTV - GIPS CPFF 8.0 8.0 8.0 8.0 8.0 40.0\\r\\n1 50296 Support.USMC OCONUS\\r\\n\\r\\n2\\r\\n\\r\\n3\\r\\n\\r\\n4\\r\\n\\r\\n5\\r\\n\\r\\n6\\r\\n\\r\\n7\\r\\n\\r\\n8\\r\\n\\r\\n9\\r\\n\\r\\n10\\r\\n\\r\\n11\\r\\n\\r\\n12\\r\\n\\r\\n13\\r\\n\\r\\n14\\r\\n\\r\\n15\\r\\nTotal Regular Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\nTotal Overtime Hours:\\r\\nTotal Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\n\\r\\nSignature: GILL JR., GARY L. (165924) By signing this timesheet you are certifying that hours were incurred on the project Approval: MCCARTHY, CHARLES W. (156593)\\r\\nDate: Dec 11, 2020 3:39:46 PM and day specified. Intentionally mischarging your time can subject you to Date: Dec 14, 2020 7:51:34 AM\\r\\ndisciplinary action as well as civil or criminal penalities.OSHKOSH CORPORATION\\r\\nEmployee Timesheet\\r\\nEmployee: JARRETT, QUINCY Revision: 1\\r\\nEmployee ID: 281196 Schedule: Weekly\\r\\nClass: Contractor Period Ending: Dec 12, 2020\\r\\nPrinted: Dec 15, 2020 6:55 AM Page: 1 of 1\\r\\nLine Project.Activity Charge Sun Mon Tue Wed Thu Fri Sat Line\\r\\nNo Cost Center Description 12/6 12/7 12/8 12/9 12/10 12/11 12/12 Totals\\r\\nP106037.B860658 JLTV LRIP/FRP Execution 8.0 8.0\\r\\n1 50296 IMS.Retrofit - FSR ECP Field\\r\\nP107016.C922206 JLTV - GIPS CPFF 8.0 8.0 8.0 8.0 32.0\\r\\n2 50296 Support.USMC OCONUS\\r\\n\\r\\n3\\r\\n\\r\\n4\\r\\n\\r\\n5\\r\\n\\r\\n6\\r\\n\\r\\n7\\r\\n\\r\\n8\\r\\n\\r\\n9\\r\\n\\r\\n10\\r\\n\\r\\n11\\r\\n\\r\\n12\\r\\n\\r\\n13\\r\\n\\r\\n14\\r\\n\\r\\n15\\r\\nTotal Regular Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\nTotal Overtime Hours:\\r\\nTotal Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\n\\r\\nSignature: JARRETT, QUINCY (281196) By signing this timesheet you are certifying that hours were incurred on the project Approval: NICDAO, ROMMEL P. (155084)\\r\\nDate: Dec 11, 2020 1:55:10 AM and day specified. Intentionally mischarging your time can subject you to Date: Dec 14, 2020 7:32:43 AM\\r\\ndisciplinary action as well as civil or criminal penalities.OSHKOSH CORPORATION\\r\\nEmployee Timesheet\\r\\nEmployee: RIVERA, JESUS Revision: 1\\r\\nEmployee ID: 275412 Schedule: Weekly\\r\\nClass: Contractor Period Ending: Dec 12, 2020\\r\\nPrinted: Dec 14, 2020 7:53 AM Page: 1 of 1\\r\\nLine Project.Activity Charge Sun Mon Tue Wed Thu Fri Sat Line\\r\\nNo Cost Center Description 12/6 12/7 12/8 12/9 12/10 12/11 12/12 Totals\\r\\nP107016.C922206 JLTV - GIPS CPFF 8.0 8.0 8.0 8.0 8.0 40.0\\r\\n1 50296 Support.USMC OCONUS\\r\\n\\r\\n2\\r\\n\\r\\n3\\r\\n\\r\\n4\\r\\n\\r\\n5\\r\\n\\r\\n6\\r\\n\\r\\n7\\r\\n\\r\\n8\\r\\n\\r\\n9\\r\\n\\r\\n10\\r\\n\\r\\n11\\r\\n\\r\\n12\\r\\n\\r\\n13\\r\\n\\r\\n14\\r\\n\\r\\n15\\r\\nTotal Regular Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\nTotal Overtime Hours:\\r\\nTotal Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\n\\r\\nSignature: RIVERA, JESUS (275412) By signing this timesheet you are certifying that hours were incurred on the project Approval: MCCARTHY, CHARLES W. (156593)\\r\\nDate: Dec 14, 2020 6:26:48 AM and day specified. Intentionally mischarging your time can subject you to Date: Dec 14, 2020 7:52:29 AM\\r\\ndisciplinary action as well as civil or criminal penalities.OSHKOSH CORPORATION\\r\\nEmployee Timesheet\\r\\nEmployee: SAWYER, ROBERT D. Revision: 1\\r\\nEmployee ID: 149147 Schedule: Weekly\\r\\nClass: Contractor Period Ending: Dec 12, 2020\\r\\nPrinted: Dec 14, 2020 7:53 AM Page: 1 of 1\\r\\nLine Project.Activity Charge Sun Mon Tue Wed Thu Fri Sat Line\\r\\nNo Cost Center Description 12/6 12/7 12/8 12/9 12/10 12/11 12/12 Totals\\r\\nP107016.C922206 JLTV - GIPS CPFF 8.0 8.0 8.0 8.0 8.0 40.0\\r\\n1 50296 Support.USMC OCONUS\\r\\n\\r\\n2\\r\\n\\r\\n3\\r\\n\\r\\n4\\r\\n\\r\\n5\\r\\n\\r\\n6\\r\\n\\r\\n7\\r\\n\\r\\n8\\r\\n\\r\\n9\\r\\n\\r\\n10\\r\\n\\r\\n11\\r\\n\\r\\n12\\r\\n\\r\\n13\\r\\n\\r\\n14\\r\\n\\r\\n15\\r\\nTotal Regular Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\nTotal Overtime Hours:\\r\\nTotal Hours: 8.0 8.0 8.0 8.0 8.0 40.0\\r\\n\\r\\nSignature: SAWYER, ROBERT D. (149147) By signing this timesheet you are certifying that hours were incurred on the project Approval: MCCARTHY, CHARLES W. (156593)\\r\\nDate: Dec 12, 2020 6:19:08 AM and day specified. Intentionally mischarging your time can subject you to Date: Dec 14, 2020 7:52:12 AM\\r\\ndisciplinary action as well as civil or criminal penalities.Jessica Liberski\\r\\nFrom: Brent Van Ark <bvanark@defense.oshkoshcorp.com>\\r\\nSent: Wednesday, December 16, 2020 8:29 AM\\r\\nTo: STSTS Care Mailbox\\r\\nCc: Rommel Nicdao; Charles Mccarthy; Barb Baier\\r\\nSubject: RE: [EXTERNAL] Expense Approval Request: JLTV WE 12/12 - Group 1 - Brent\\r\\n\\r\\nOshkosh Corporation Classification ‐ Restricted\\r\\n\\r\\nGoo morning,\\r\\n\\r\\nGroup 1 is approved.\\r\\n\\r\\nThank you,\\r\\n\\r\\nBrent Van Ark\\r\\nJLTV Service Supervisor\\r\\nOshkosh Defense, LLC\\r\\n\\r\\nOffice (920) 235- 9151 Ext. 25916 Mobile: (920) 216- 1368\\r\\n2307 Oregon Street, Oshkosh, WI 54902\\r\\nBvanark@defense.oshkoshcorp.com\\r\\n\\r\\nFrom: STSTS Care Mailbox <care@ststechnicaljobs.com>\\r\\nSent: Tuesday, December 15, 2020 3:54 PM\\r\\nTo: Brent Van Ark <bvanark@defense.oshkoshcorp.com>\\r\\nCc: Rommel Nicdao <rnicdao@defense.oshkoshcorp.com>; Charles Mccarthy <cmccarthy@defense.oshkoshcorp.com>;\\r\\nBarb Baier <bbaier@defense.oshkoshcorp.com>; STSTS Care Mailbox <care@ststechnicaljobs.com>\\r\\nSubject: [EXTERNAL] Expense Approval Request: JLTV WE 12/12 ‐ Group 1 ‐ Brent\\r\\n\\r\\nAttention: This email originated from outside of the organization.\\r\\n\\r\\nHi Brent,\\r\\n\\r\\nHere is your group for the week – Please let us know if these are all set \\r\\n\\r\\nLast First  Last  First\\r\\nAhrens Daniel  Hall Timothy\\r\\nAnderson Ronald  Hane Keith\\r\\nAnthony Ray  Harding Chadwick\\r\\nBaker Gregory  Helton Steven\\r\\nBanks Michael  Hernandez Benjamin\\r\\nBehne Jack  Hernandez Christopher\\r\\nBennett Ryan  Hobbs Vernon\\r\\nBiggerstaff Robert  Hopkins Thomas\\r\\n\\r\\n1Booker\\r\\nBooker\\r\\nBrown\\r\\nBrunson\\r\\nBuckner\\r\\nBurrow\\r\\nCampbell\\r\\nCampbell\\r\\nCanganelli\\r\\nChavez\\r\\nCollins\\r\\nCook\\r\\nCrespo Cruz\\r\\nCross\\r\\nDailey\\r\\nDake\\r\\nDavis\\r\\nDe Luna\\r\\nDeloach\\r\\nDixon\\r\\nDoyle\\r\\nDustin\\r\\nElliott\\r\\nEvans\\r\\nEvans\\r\\nFlora\\r\\nFlores\\r\\nForbes\\r\\nFrink\\r\\nGates\\r\\nGathright\\r\\nGomez\\r\\nGonzalez\\r\\nGonzalez\\r\\nGrant\\r\\nGreen\\r\\nGrullon\\r\\nGuertin\\r\\nHabenicht\\r\\nHailey\\r\\nJoshua\\r\\nNathaniel\\r\\nMoses\\r\\nDelvin\\r\\nKennan\\r\\nToney\\r\\nRobert\\r\\nSharon Felomenia\\r\\nEli\\r\\nRosario\\r\\nQuincy\\r\\nJames\\r\\nFerdinand\\r\\nJustin\\r\\nAlbert\\r\\nDavid\\r\\nPhillip\\r\\nChristopher\\r\\nTravarus\\r\\nKeith\\r\\nTimothy\\r\\nHarold\\r\\nJason\\r\\nPatrick\\r\\nRochell\\r\\nJames\\r\\nJosue\\r\\nPatrick\\r\\nHerbert\\r\\nSteven\\r\\nMichael\\r\\nRuben\\r\\nMario\\r\\nSergio\\r\\nDevante\\r\\nMichael\\r\\nJuan\\r\\nPatrick\\r\\nRebecca\\r\\nDavid\\r\\nHorjus\\r\\nHuddleston\\r\\nHylan\\r\\nJames\\r\\nJarrett\\r\\nJohnson\\r\\nKubik\\r\\nLaitan\\r\\nLawson\\r\\nLewis\\r\\nLove\\r\\nLovelace\\r\\nMartinez\\r\\nMassari\\r\\nMcCray\\r\\nMcIntosh\\r\\nMiller\\r\\nMyers\\r\\nPacheco\\r\\nPenn Nash\\r\\nPine\\r\\nPorras\\r\\nRichardson\\r\\nRobinett\\r\\nRosemond\\r\\nRoss\\r\\nSanders\\r\\nSawyer\\r\\nSeeley\\r\\nShoemake\\r\\nSlaughter\\r\\nSmith\\r\\nSmith\\r\\nSmith\\r\\nStarkenburg\\r\\nStuart\\r\\nTremblay\\r\\nWilliams\\r\\nWilson\\r\\nWinston\\r\\nAndrew\\r\\nKevin\\r\\nDavid\\r\\nMontrayal\\r\\nQuincy\\r\\nJohn F K\\r\\nEric\\r\\nKenneth\\r\\nRonald\\r\\nHarold\\r\\nJerry\\r\\nRickey\\r\\nJuan\\r\\nJason\\r\\nAndre\\r\\nCliff\\r\\nRobert\\r\\nJames\\r\\nLuis\\r\\nDion\\r\\nLeighton\\r\\nFrancisco\\r\\nGarold\\r\\nGannon\\r\\nBryan\\r\\nShawn\\r\\nRoger\\r\\nRobert\\r\\nTerry\\r\\nVincent\\r\\nJeremy\\r\\nKelvin\\r\\nMichael\\r\\nTodd\\r\\nBarry\\r\\nDaniel\\r\\nJoseph\\r\\nAnthony J\\r\\nGreen\\r\\nLarry\\r\\n\\r\\nThanks!\\r\\nJessica Liberski\\r\\nOperations Specialist\\r\\nSTS Technical Services\\r\\n2(262) 439-7525 • Cell: (920) 883-6861\\r\\nCare: 800-800-2400 x3913\\r\\nFax: (888) 611-1950\\r\\n\\r\\nSolutions To Keep You...\\r\\nEngineering • Manufacturing • Operating • Maintaining\\r\\nPlease take the Work Opportunity Tax Credit (WOTC) survey\\r\\n\\r\\nThis email was scanned by Bitdefender\\r\\n\\r\\nAlthough this e-mail and any attachments are believed to be free of any virus or other defect which might affect\\r\\nany computer system, it is the responsibility of the recipient to check that it is virus-free and the sender accepts\\r\\nno responsibility or liability for any loss, injury, damage, cost or expense arising in any way from receipt or use\\r\\nthereof by the recipient.\\r\\n\\r\\nThe information contained in this electronic mail message is confidential information and intended only for the\\r\\nuse of the individual or entity named above, and may be privileged. If the reader of this message is not the\\r\\nintended recipient, you are hereby notified that any dissemination, distribution or copying of this\\r\\ncommunication is strictly prohibited. If you have received this transmission in error, please contact the sender\\r\\nimmediately, delete this material from your computer ...", "level": "Information", "logType": "User", "timeStamp": "23:01:55", "processVersion": "1.0.3", "jobId": "486869b0-5d90-4d5b-855f-16661c6c9962", "robotName": "Suha Alhabaj", "machineId": 22, "organizationUnitId": 1, "fileName": "Read_Invoice" }'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php