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

Substitution
Processing...

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 = "[\\041-\\176]+:"; final String string = "From xjackh+caf_=xjackh=jrh.sh@gmail.com Wed Oct 29 03:20:52 2025\n" + "Return-path: <xjackh+caf_=xjackh=jrh.sh@gmail.com>\n" + "Envelope-to: xjackh@jrh.sh\n" + "Delivery-date: Wed, 29 Oct 2025 03:20:52 +0000\n" + "Received: from mail-wr1-f47.google.com ([209.85.221.47])\n" + " by glacier.mxrouting.net with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384\n" + " (Exim 4.98)\n" + " (envelope-from <xjackh+caf_=xjackh=jrh.sh@gmail.com>)\n" + " id 1vDwjz-0000000G5kY-0gU6\n" + " for xjackh@jrh.sh;\n" + " Wed, 29 Oct 2025 03:20:52 +0000\n" + "Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-42701b29a7eso271232f8f.0\n" + " for <xjackh@jrh.sh>; Tue, 28 Oct 2025 20:20:51 -0700 (PDT)\n" + "ARC-Seal: i=2; a=rsa-sha256; t=1761708050; cv=pass;\n" + " d=google.com; s=arc-20240605;\n" + " b=C7UZsXpJzrPnSJQiHi0mAcFAbVyAsGlBvcU0IQJte4IF+nItmMwEsuwnkzmiTSDJp8\n" + " 4O0Xys78bHJFwNByPb6f9OSblqs6HGOjwBPqK1iaQyOjjtPJaHvRuK9DVKOY1JJxV1Fw\n" + " lSNrIxRQnUrm4C5fVzHWfRoN736l4Jzil+RzUlEGNiuVNIa2XcN0owUaNijfdDgIVV2T\n" + " VDz1966jTfmGvG4iKL6qd937Hdl4spHRE/XK2cHWWucBTKYuri7t0ib8UTZaoMxXPVgp\n" + " TXRzK+9j8yvNm/spUvz36imPloWfr8DJlL57/UVJS7SZl+ydAJwKtjAyfacxZgNxm+02\n" + " Z7xw==\n" + "ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;\n" + " h=feedback-id:mime-version:subject:to:from:date:dkim-signature\n" + " :message-id:delivered-to;\n" + " bh=vRmniYCYXVIAiIJPuHtSj29f2zefOZCS2+LWmfWbcZw=;\n" + " fh=JwjRhZczYpEeTfVk3p/cxXR1iOjJ+oSrnKTBEmypBlc=;\n" + " b=GZZFdTjV88vU87OjprcOIBM/vEt5u6H+z5i7Yp+wvtzQkgMm6yUSEWjdUhaB3MGdXh\n" + " 1reAy/lDqEsH7nRaS/l1HfICe50G6qAMm5z36AoJ0dFU6j9hp5/CeWy3Dm22MjWYZb5h\n" + " L/7RXOCCLGdiGIbDyfy63hslLe4rfM4nLYbwnfiUs/Y9yBoeLPb4UZoOLcljMreSjvRB\n" + " E1fQSNHGa3vj0llVqU8JngotTcZ9KJ6lpUiDe4dDN9bsRQz0YlK5iyRFiVvfMQl+teH9\n" + " Kznj0PBRSE71Iw8HrqJx3/XXKJhArAtedzmbKhErxvGHYbbIRHPvXL29rx5iVGkfaVWJ\n" + " XyVQ==;\n" + " darn=jrh.sh\n" + "ARC-Authentication-Results: i=2; mx.google.com;\n" + " dkim=pass header.i=@deals.aliexpress.com header.s=aliyun-ap-southeast-1 header.b=NGVAU49w;\n" + " spf=pass (google.com: domain of ae-report.ae0@deals.aliexpress.com designates 8.219.33.24 as permitted sender) smtp.mailfrom=ae-report.ae0@deals.aliexpress.com;\n" + " dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=deals.aliexpress.com\n" + "X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n" + " d=1e100.net; s=20230601; t=1761708050; x=1762312850;\n" + " h=feedback-id:mime-version:subject:to:from:date:dkim-signature\n" + " :message-id:delivered-to:x-forwarded-for:x-forwarded-to\n" + " :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;\n" + " bh=vRmniYCYXVIAiIJPuHtSj29f2zefOZCS2+LWmfWbcZw=;\n" + " b=CDKe4dMV3sXqRJogOxq5XlcgiFB9wEhUjF67Iy/zX6u1wdB6aysXIc0a0fTfkjfs5F\n" + " /SWPpkGXt3zcPw03C9dv55+3GGrILLbPAc3Br4Ijrb1Ts/900yfIwRIpCiJt8UVw3Jzm\n" + " It9ggGW9L7Oaml4//pLBTJ95bpvSzfl4DGANsKl8bD5hWqW+pP0VdscG+vLuujb51y5p\n" + " gux0KkJBOTQI3hqPiXJbnsZRtr7CoK5ujZiKS6FgpKI2VjZFcZLXWO+cdT00bvQgbkSf\n" + " bfpMDope4CHeO4GOrYDgZWRUUz8nP+wuTkRQzJ2hkXkjrFafvJc6ZmhT6IDhiuetQQWX\n" + " Wszg==\n" + "X-Forwarded-Encrypted: i=2; AJvYcCXtwG/Ac4/Y20TzZ0+EFUXLkbbe8dqyXqYZy8yO1H8ppFI9jwaeAF04VJzefACzq4qh7PISS68=@jrh.sh\n" + "X-Gm-Message-State: AOJu0YxEYfh4YdjC/SBefQvWNRIR5ljkN7QoR9DoBTV2PkBlgGwNWlZM\n" + " xp5L/IhMgTVIK1kKCisMKdt9eNAGhV3qPQa4em7FfMQrIDyvsnetGZMQ+J6XCrw7YZ0f4gP+6TL\n" + " K4xcJFlHY03oMoFkcmgMo5YPdKWCcGVOyyJ7vWZu6RALsQMKn1xZgu+lZEKrViQ==\n" + "X-Received: by 2002:a05:6000:24c9:b0:425:86b1:113a with SMTP id ffacd0b85a97d-429a81ea702mr5073556f8f.16.1761708050052;\n" + " Tue, 28 Oct 2025 20:20:50 -0700 (PDT)\n" + "X-Forwarded-To: xjackh@jrh.sh\n" + "X-Forwarded-For: xjackh@gmail.com xjackh@jrh.sh\n" + "Delivered-To: xjackh@gmail.com\n" + "Received: by 2002:a05:6000:dc2:b0:427:632:4190 with SMTP id dw2csp1860918wrb;\n" + " Tue, 28 Oct 2025 20:20:48 -0700 (PDT)\n" + "X-Google-Smtp-Source: AGHT+IHUfXjUwENcjOwEXkBNZOE2CifXw4FktUj3SSaAtc+U0MfF8DPDHBUVz0mkDFonGhHjgnS7\n" + "X-Received: by 2002:a05:6a20:9150:b0:33f:df99:11ed with SMTP id adf61e73a8af0-34653337a2dmr1903058637.24.1761708048038;\n" + " Tue, 28 Oct 2025 20:20:48 -0700 (PDT)\n" + "ARC-Seal: i=1; a=rsa-sha256; t=1761708048; cv=none;\n" + " d=google.com; s=arc-20240605;\n" + " b=CdPvEAo+IvoLoWxQdCxBXW+3puMPQkidzNrcardKvVoYuE4S/Ml4i6d6aUICqc4ydP\n" + " 9BaC/lyHBS/VgcanoGHrzHq0OJOQr3fJvWe7elAO6B9PFFriRvB1KLukyhXQlvGgiKOw\n" + " Cq8rARb7QF8Mki/I4B7IUYfQg3c0VSo8sWKhTaBJ4v+V2hmMS3pyXGgUvMrDNKW1p+fg\n" + " hLUtFH38ruXgN+KUbeq4JrzsHzANNwOjWsJLa81Rtw3ljq3v2qMnmxMjdm5moN4gDPMI\n" + " agu0LM2pZDh15mV7EE0c/uC1z0Yqr7/IUdhkT+AvFdT0EpVMm5jIRpxLL5JMgoPnd2OX\n" + " 1Seg==\n" + "ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;\n" + " h=feedback-id:mime-version:subject:to:from:date:dkim-signature\n" + " :message-id;\n" + " bh=vRmniYCYXVIAiIJPuHtSj29f2zefOZCS2+LWmfWbcZw=;\n" + " fh=qR5+LTh/3Ua36ecBQvpnRfVCaHh2O6Cn2Gj2Y9qDsqY=;\n" + " b=EhytWeDKTraXyOId3sr9UHnlMtINFtjNLWzOC0VgAM4S0utspBQXKDSS4rdPpUGFxU\n" + " m6zAnV+d2XYEnhQFOmU9hcyukxfkh3Ry3aBtnLcgVzpIEKCHo56ZGnoaPZYAybpd+nyX\n" + " mMiAMyEPASbRmpUaJ6Y6QhbYvujTVx+kDPAYbQdVxmuFRW6HxeC8sShWe86qoLt8ey+e\n" + " kxMAGyuQLe8N2Pzfax3aQYAQShI9Sz3b9gRad1xjlThCQF5TrRhxOrP2gdZiVfM4PJzm\n" + " UmIpARLVfyE5ArlWf8RXtGq8tt4hplTeSmBO0ZDxUm3PucYZz7S/9ahqO8fDATnTGnLT\n" + " oJ6Q==;\n" + " dara=google.com\n" + "ARC-Authentication-Results: i=1; mx.google.com;\n" + " dkim=pass header.i=@deals.aliexpress.com header.s=aliyun-ap-southeast-1 header.b=NGVAU49w;\n" + " spf=pass (google.com: domain of ae-report.ae0@deals.aliexpress.com designates 8.219.33.24 as permitted sender) smtp.mailfrom=ae-report.ae0@deals.aliexpress.com;\n" + " dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=deals.aliexpress.com\n" + "Received: from out33-24.sg.b.dm.aliyun.com (out33-24.sg.b.dm.aliyun.com. [8.219.33.24])\n" + " by mx.google.com with ESMTPS id 41be03b00d2f7-b71f4ba78d2si6202184a12.1047.2025.10.28.20.20.46\n" + " for <xjackh@gmail.com>\n" + " (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n" + " Tue, 28 Oct 2025 20:20:48 -0700 (PDT)\n" + "Received-SPF: pass (google.com: domain of ae-report.ae0@deals.aliexpress.com designates 8.219.33.24 as permitted sender) client-ip=8.219.33.24;\n" + "Authentication-Results: mx.google.com;\n" + " dkim=pass header.i=@deals.aliexpress.com header.s=aliyun-ap-southeast-1 header.b=NGVAU49w;\n" + " spf=pass (google.com: domain of ae-report.ae0@deals.aliexpress.com designates 8.219.33.24 as permitted sender) smtp.mailfrom=ae-report.ae0@deals.aliexpress.com;\n" + " dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=deals.aliexpress.com\n" + "Message-ID: <69018810.050a0220.cfe87.f51eSMTPIN_ADDED_BROKEN@mx.google.com>\n" + "X-Google-Original-Message-ID: <9871biz_add_cart:0:0_579222405$432bfbabec63491d8a77746119e0e945@deals.aliexpress.com>\n" + "X-AliDM-RcptTo: eGphY2toQGdtYWlsLmNvbQ==\n" + "DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed;\n" + " d=deals.aliexpress.com; s=aliyun-ap-southeast-1;\n" + " t=1761708046; h=Date:From:To:Message-ID:Subject:MIME-Version:Content-Type;\n" + " bh=vRmniYCYXVIAiIJPuHtSj29f2zefOZCS2+LWmfWbcZw=;\n" + " b=NGVAU49w8Ms5d9xgiygPUkwxi9ZflULR710SmP0ZJbigzvY/AUmUwWI24T7cwBeEVFV2P3O73AkfiWeCDqxs4oxCviAkM/2TLMn9+60TCpZ8nbvv3TRdrnikjzmDui4qO09YbehtghFhVksQKhGTDEJleZ0caAV1ZWUMaWtfl/o=\n" + "Received: from ae-ut-crab-s033065010130.sg52(mailfrom:ae-report.ae0@deals.aliexpress.com fp:SMTPD_4w3hQ..1XR5 cluster:dm-ay35sg-a)\n" + " by smtp.aliyun-inc.com(127.0.0.1);\n" + " Wed, 29 Oct 2025 11:20:45 +0800\n" + "X-EnvId: 8000000150423353160\n" + "Date: Tue, 28 Oct 2025 20:20:45 -0700 (PDT)\n" + "From: AliExpress <ae-report.ae0@deals.aliexpress.com>\n" + "To: xjackh@gmail.com\n" + "MIME-Version: 1.0\n" + "Content-Type: multipart/mixed; \n" + " boundary=\"----=_Part_1025839_1127131696.1761708045971\"\n" + "X-250ok-CID: 42c31aa6232f4990b1f5c6437dc13f99\n" + "Feedback-ID: trigger_biz_add_cart-0:ae-report.ae0@deals.aliexpress.com:S-100001:151973\n" + "X-DKIM: signer='deals.aliexpress.com' status='fail' reason='signature_incorrect'\n" + "DKIMCheck: Server failed DKIM test, 50 Spam score\n" + "X-Spam-Score: 6.2 (++++++)\n" + "X-Spam-Report: Spam detection software, running on the system \"glacier.mxrouting.net\", has\n" + " performed the tests listed below against this email.\n" + " Information: https://mxroutedocs.com/directadmin/spamfilters/\n" + " ---\n" + " Content analysis details: (6.2 points)\n" + " ---\n" + " pts rule name description\n" + " ---- ---------------------- -----------------------------------------\n" + " 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked.\n" + " See\n" + " http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block\n" + " for more information.\n" + " [URI: aliexpress.com]\n" + " [URI: mmstat.com]\n" + " [URI: fonts.googleapis.com]\n" + " 0.0 RCVD_IN_DNSWL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to DNSWL\n" + " was blocked. See\n" + " http://wiki.apache.org/spamassassin/DnsBlocklists#DnsBlocklists-dnsbl-block\n" + " for more information.\n" + " [209.85.221.47 listed in list.dnswl.org]\n" + " 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record\n" + " 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid\n" + " 0.0 ARC_SIGNED Message has a ARC signature\n" + " 0.0 ARC_VALID Message has a valid ARC signature\n" + " 0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid\n" + " 0.0 KAM_DMARC_STATUS Test Rule for DKIM or SPF Failure with Strict\n" + " Alignment\n" + " 1.5 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail\n" + " domains are different\n" + " 1.0 HTML_FONT_LOW_CONTRAST BODY: HTML font color similar or identical to\n" + " background\n" + " 1.5 HTML_MESSAGE BODY: HTML included in message\n" + " 2.0 MIME_HTML_ONLY BODY: Message only has text/html MIME parts\n" + " 0.0 HTML_IMAGE_RATIO_04 BODY: HTML has a low ratio of text to image area\n" + " 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay\n" + "X-Old-Subject:Good choice, your faves await!\n" + "Subject:Good choice, your faves await!\n" + "X-Spam-Status: Yes, score=6.2, +20 total spam score\n" + "SpamTally: Final spam score: 132\n\n" + "------=_Part_1025839_1127131696.1761708045971\n" + "Content-Type: text/html;charset=utf-8\n" + "Content-Transfer-Encoding: quoted-printable\n\n" + "<-- BODY SNIPPED HERE -->\n\n" + "------=_Part_1025839_1127131696.1761708045971--"; final String subst = ""; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceAll(subst); System.out.println("Substitution result: " + 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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html