Regular Expressions 101

Save & Share

  • Save new Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s
  • Add to Community Library

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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
gm

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(?<=\\((No.\\)) : )(.+)"; final String string = "CÔNG TY TNHH GRAB\n" + "Địa chỉ (Address) :Tòa nhà Mapletree Business Centre, 1060 Nguyễn Văn Linh, Phường Tân Phong, Quận 7,\n" + "Thành phố Hồ Chí Minh, Việt Nam\n" + "Mã số thuế (Tax code) :0 3 1 2 6 5 0 4 3 7\n\n" + "HÓA ĐƠN GIÁ TRỊ GIA TĂNG\n" + "(VAT INVOICE) Ký hiệu (Serial) : 1C22TGN\n" + "Ngày (Date) 23 tháng (month) 05 năm (year) 2022 Số (No.) : 1117609\n" + " \n" + "Mã của CQT: 00AD14CC7603364466BF60F761D05D6A13\n\n" + "Họ tên người mua hàng (Customer's name) :\n" + "(Xuất bởi phần mềm EInvoice, Công ty TNHH Phát triển công nghệ Thái Sơn - MST: 0101300842 - www.einvoice.vn)\n" + "Tên đơn vị (Company) :CÔNG TY TNHH UN-AVAILABLE\n" + "Mã số thuế (Tax code) :0303271471\n" + "Địa chỉ (Address) :Một phần lô I/3 Đường số 7, Khu công nghiệp Vĩnh Lộc, Phường Bình Hưng Hòa B, Quận Bình Tân,\n" + "TP Hồ Chí Minh, Việt Nam\n" + "Hình thức thanh toán (Payment term) :Chuyển khoản Số tài khoản (Bank A/C) :\n\n" + "STT Tên hàng hóa, dịch vụ ĐVT Số lượng Đơn giá Thuế suất Thành tiền Tiền thuế Thành tiền\n" + "trước thuế\n" + "(No.) (Description) (Unit) (Quantity) (Unit Price) (Tax rate) (Amount exc VAT) (VAT amount) (Selling price)\n" + "A B C D E F G = I / (1+ F) H = I - G I\n" + "Cước phí vận chuyển mã\n" + "1 A-3ENBVDNWWJFL Chuyến 1 9.091 10% 9.091 909 10.000\n" + "(phần doanh thu Grab\n" + "được chia)\n" + "Cước phí vận chuyển mã\n" + "2 A-3ENBVDNWWJFL Chuyến 1 36.364 10% 36.364 3.636 40.000\n" + "(phần doanh thu của đối\n" + "tác vận tải)\n" + " \n" + " \n" + " \n" + "Tổng cộng số tiền đã có thuế GTGT: 50.000\n" + "(Total of VAT included selling price) :\n" + "Tổng tiền trước thuế 10%: 45.455 Tổng tiền thuế 10%: 4.545\n" + "(Total of amount exc VAT 10%) (Total of VAT amount 10%)\n" + "Trong đó: Tổng tiền trước thuế 5%: Tổng tiền thuế 5%: \n" + "(in which) (Total of amount exc VAT 5%) (Total of VAT amount 5%)\n" + "Tổng cộng số tiền trước thuế: 45.455 Tổng tiền thuế GTGT: 4.545\n" + "(Total of amount exc VAT) (Total of VAT amount)\n\n" + "Số tiền viết bằng chữ (Amount in words) : Năm mươi nghìn đồng\n\n" + "Người mua hàng (Buyer) Người bán hàng (Seller)\n" + "(Ký, ghi rõ họ tên) (Ký, đóng dấu, ghi rõ họ tên)\n" + "(Signature & full name) (Signature, stamp & full name)\n\n" + "Signature Valid \n" + " Ký bởi: CÔNG TY TNHH GRAB\n" + "Ký ngày: 23/05/2022\n\n" + "Mã nhận hóa đơn (Code for checking): QIEJWLAEYGQ5 tra cứu tại (Tracking): https://vn.invoice.grab.com/\n" + "Ghi chú: Thành tiền (giá bán) là giá đã bao gồm thuế GTGT. (Note: Selling price is VAT included)\n" + "(Cần kiểm tra, đối chiếu khi lập, giao, nhận hóa đơn / Need to check, compare when making, delivering, receiving invoices)\n" + "Trang 1/1"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html