Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"[0-9]{2}[-|\/]{1}[0-9]{2}[-|\/]{1}[0-9]{4}", flags=re.MULTILINE) test_str = ("03-Feb-2021\n" "Mr./Ms. JOHN THACHIL\n" "MADHURA SURAKSHA APARTMENT\n" "S6 2ND FLOOR\n" "JP NAGAR 5TH PHASE\n" "BANGALORE 560078\n" "Dear Customer, \n" "Subject: EasyEMI on your HDFC Bank Credit Card Number:552260XXXXXX0961\n" "We are pleased to grant you the EasyEMI payment facility as per the details stated below. The\n" "transaction amount has been converted into EasyEMI as per your request\n" "EasyEMI Loan no. 0000000000065214714\n" "Unsecured Loan Type EasyEMI\n" "Amount Rs.3399.00\n" "Tenure 3 Months\n" "EasyEMI Fixed Finance Charges on Reducing Balance 1.25% p.m.\n" "EMI Amount Rs.1161.44(Excluding GST)*\n" "Merchant Name \n" "Processing Fee Rs.199.00\n" "*GST at 18% will be charged on the following and are subjected to change as per Govt.Announcement:\n" "1.EasyEMI Finance Charges Component on the EMI amount on a monthly basis\n" "2.Processing fee, if any\n" "3.Pre-closure charges, if any\n" "Please refer to the enclosed amortization schedule for EMI details\n" "For the first EMI, the interest will be calculated from the loan booking date till the payment due date. This\n" "is effective only for loans booked from Feb 2019 onwards.In case you require any further assistance , pls\n" "contact Phone Banking within 7 days of receiving this letter\n" "EasyEMI transactions are not eligible for Reward Points.This EasyEMI can be pre-closed anytime during the\n" "tenure. In case of pre-closure of the EasyEMI facility, there will be no Penalty levied currently. As the pre-closure\n" "charge is subjected to change, we request you to get in touch with your nearest call centre for the applicable\n" "charge, if any, if you decide to pre-close the EasyEMI. Partial pre-payment or partial closure is not permitted on\n" "this loan\n" "Additional Finance Charges if any on the principal outstanding from last statement date till date of loan pre-\n" "closure need to be paid by customer.\n" "Please also note that the above mentioned EMI amounts will be included to your monthly HDFC Bank Credit Card\n" "statements and will be payable as part of the Minimum Amount Due.\n" "If your HDFC Bank Card gets closed before all the installments have been charged, the loan outstanding will get\n" "debited to your card account and you’re expected to pay the amount in full. In case of default in payment of credit\n" "card dues or EMIs by the due dates, your card account is liable to be suspended and could further be terminated.\n" "The terms and conditions contained in the Cardmember Agreement apply over and above the terms and\n" "conditions for this loan. In case you do not agree to any of the details above, or require any further assistance,\n" "please contact the nearest customer service call centre at the numbers provided below, within 7 days of receiving\n" "this letter.\n" "Enclosed Amortization schedule of Loan Number 0000000000065214714 for Loan Amount Rs.3399.00\n" "(*GST extra @18% on Interest Component)\n" "NoNo\n" "EasyEMIEasyEMI\n" "StatementPrincipalEMIBalanceStatementPrincipalEMIBalance\n" "FinanceFinance\n" "DateAmountAmountDateAmountAmount\n" "ChargesCharges\n" "onon\n" "ReducingReducing\n" "BalanceBalance\n" "21-02-202121-04-2021\n" "11118.9670.881189.842280.0431147.1014.331161.430.00\n" "21-03-2021\n" "21132.9428.501161.441147.10\n" "This is a computer generated letter and does not require a signature.") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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 Python, please visit: https://docs.python.org/3/library/re.html