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

/
/
gm

Test String

Code Generator

Generated Code

// include the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r#"(?m)<div\s+id="lark-mail-quote-[^<>]+>"#).unwrap(); let string = "<div style=\"list-style-position: inside; margin-top: 16px;\" id=\"lark-mail-quote-164500864\" class=\"quote1645084723054 quoteRendered\"><div class=\"adit-html-block adit-html-block--collapsed\"><div style=\"width: 100%; height: 1px; margin-top: 16px; padding-top: 16px; border-top-width: 1px; border-top-style: solid; border-top-color: rgb(222, 224, 227); display: none;\" id=\"quote-divider-line\"></div><div><div style=\"color:rgb(143, 149, 158)\" class=\"adit-html-block__attr\"><div id=\"lark-mail-quote-1013dab007b34a9dc6d40d1f3df7deaa\" class=\"quoteRendered\"><div id=\"lark-mail-quote-6f7b0bbbbcdd7c4219b05c0fd16606c1\" class=\"quoteRendered\"><div style=\"padding-bottom:8px;word-break:break-word;color:#8F959E !important\"><div style=\"color:#8F959E !important\"><span style=\"color:#646A73\">发件人:</span><span style=\"white-space:normal\">\"蓝灿荣\"&lt;<a style=\"overflow-wrap:break-word;white-space:pre-wrap;hyphens:auto;word-break:break-word;cursor:pointer;text-decoration:none;color:unset\" href=\"mailto:lancanrong@bytedance.com\" rel=\"nofollow noopener noreferrer\">lancanrong@bytedance.com</a>&gt;</span></div><div style=\"color:#8F959E !important\"><span style=\"color:#646A73\">时间:</span> 2022年2月16日 (周三) 18:50</div><div style=\"color:#8F959E !important\"><span style=\"color:#646A73\">主题:</span> 回复:[External] 测试邮件引用-新旧新旧</div><div style=\"color:#8F959E !important\"><span style=\"color:#646A73\">收件人:</span><span style=\"white-space:normal\">\"lancanrong\"&lt;<a style=\"overflow-wrap:break-word;white-space:pre-wrap;hyphens:auto;word-break:break-word;cursor:pointer;text-decoration:none;color:unset\" href=\"mailto:lancanrong1@zijietiaodongs.top\" rel=\"nofollow noopener noreferrer\">lancanrong1@zijietiaodongs.top</a>&gt;</span></div></div></div></div></div><div style=\"margin-top:8px\"><div><div><div style=\"line-height:1.6;font-size:0.875rem\"><div dir=\"auto\" class=\"\"><span>444444444444444444444444444444444444</span></div><div id=\"lark-mail-quote-164500862\" style=\"padding-left:12px;border-left:0.5px solid rgb(187,191,196)\" class=\"quoteRendered\"><div><blockquote style=\"padding:0px;margin:0px\" id=\"lark-mail-block-content-164500862\" class=\"\"><div id=\"lark-mail-quote-35f365c7aff801f9d443621343497d1c\" class=\"quoteRendered\"><div id=\"lark-mail-quote-07788d8c442dc2ee4e026d9ae58bddfa\" class=\"quoteRendered\"><div style=\"color:rgb(143,149,158)\" id=\"lark-mail-block-attr-164500862\" class=\"\">于2022年2月16日 (周三) 18:50 &lt;<a style=\"color:rgb(51,112,255)\" href=\"mailto:lancanrong1@zijietiaodongs.top\" rel=\"nofollow noopener noreferrer\">lancanrong1@zijietiaodongs.top</a>&gt; 写道:</div><blockquote id=\"lark-mail-block-content-164500862\" class=\"\" style=\"padding:0px;margin:8px 0px 0px\"><div><div style=\"white-space:pre-wrap;white-space:pre-wrap;margin-top:4px;margin-bottom:4px;line-height:1.6\">333333333333333333333333333333333333333333333333333 </div><div id=\"lark-mail-quote-164500860\" style=\"list-style-position:inside;margin-top:12px\" class=\"quoteRendered\"><div class=\"adit-html-block adit-html-block--collapsed\"><div style=\"width:100%;height:1px;margin-top:16px;padding-top:16px;border-top-width:1px;border-top-style:solid;border-top-color:rgb(222,224,227)\"></div><div><div id=\"lark-mail-block-attr-164500862\" class=\"\" style=\"color:rgb(143,149,158)\"><div style=\"margin-top:12px\" id=\"lark-mail-quote-5713ee9ef8fa0880a0db5aca669dc892\" class=\"quoteRendered\"><div style=\"margin-top:12px\" id=\"lark-mail-quote-1a8ef6be06d3729d44846305e872806d\" class=\"quoteRendered\"><div style=\"padding-bottom:8px;word-break:break-word;color:#8f959e!important\"><div style=\"color:#8f959e!important\"><span style=\"color:#646a73\">发件人:</span><span style=\"white-space:normal\">\"蓝灿荣\"&lt;<a href=\"mailto:lancanrong@bytedance.com\" style=\"white-space:pre-wrap;word-break:break-word;text-decoration:none;color:rgb(51,112,255)\" rel=\"nofollow noopener noreferrer\">lancanrong@bytedance.com</a>&gt;</span></div><div style=\"color:#8f959e!important\"><span style=\"color:#646a73\">时间:</span> 2022年2月16日 (周三) 18:49</div><div style=\"color:#8f959e!important\"><span style=\"color:#646a73\">主题:</span> 回复:[External] 测试邮件引用-新旧新旧</div><div style=\"color:#8f959e!important\"><span style=\"color:#646a73\">收件人:</span><span style=\"white-space:normal\">\"lancanrong\"&lt;<a href=\"mailto:lancanrong1@zijietiaodongs.top\" style=\"white-space:pre-wrap;word-break:break-word;text-decoration:none;color:unset\" rel=\"nofollow noopener noreferrer\">lancanrong1@zijietiaodongs.top</a>&gt;</span></div></div></div></div></div><div style=\"margin-top:8px\"><div><div><div style=\"line-height:1.6;font-size:0.875rem\"><div class=\"\" dir=\"auto\"><span>22222222222222222222222222222222222222222222222222222</span></div><div class=\"quoteRendered\" style=\"padding-left:12px;border-left:0.5px solid rgb(187,191,196);margin-top:12px\" id=\"lark-mail-quote-164500858\"><div><blockquote class=\"\" id=\"lark-mail-block-content-164500858\" style=\"padding:0px;margin:0px\"><div style=\"margin-top:12px\" id=\"lark-mail-quote-f9f9c5db21625596a309d374d3cbde00\" class=\"quoteRendered\"><div style=\"margin-top:12px\" id=\"lark-mail-quote-c697014ae5f2a77a28ee6d25e2e4be6e\" class=\"quoteRendered\"><div class=\"\" id=\"lark-mail-block-attr-164500858\" style=\"color:rgb(143,149,158)\">于2022年2月16日 (周三) 18:49 &lt;<a href=\"mailto:lancanrong1@zijietiaodongs.top\" style=\"color:rgb(51,112,255)\" rel=\"nofollow noopener noreferrer\">lancanrong1@zijietiaodongs.top</a>&gt; 写道:</div><blockquote style=\"padding:0px;margin:8px 0px 0px\" class=\"\" id=\"lark-mail-block-content-164500858\"><div><div style=\"white-space:pre-wrap;white-space:pre-wrap;margin-top:4px;margin-bottom:4px;line-height:1.6\">111111111111111111111111111 </div><div style=\"white-space:pre-wrap;margin-top:4px;margin-bottom:4px;line-height:1.6;text-align:left\"><img data-realheight=\"280\" data-realwidth=\"280\" style=\"max-width: 100%; height: auto; max-height: none;\" src=\"cid:3881ACB5-1580-41CA-8098-38694DB9774E_msgTokenboxcnMHsyNi36OGbKUMVR0WQRCc\" loading=\"cid:3881ACB5-1580-41CA-8098-38694DB9774E_msgTokenboxcnMHsyNi36OGbKUMVR0WQRCc\"></div><div></div><div> 顶顶顶顶顶顶顶顶</div><div> 撒发达分的的撒打发灌灌灌灌灌灌灌灌</div><div style=\"white-space:pre-wrap;margin-top:4px;margin-bottom:4px;line-height:1.6\"></div></div></blockquote></div></div></blockquote></div></div></div></div></div></div></div></div></div><div style=\"white-space:pre-wrap;margin-top:4px;margin-bottom:4px;line-height:1.6;text-align:left\"><img src=\"cid:3881ACB5-1580-41CA-8098-38694DB9774E_msgTokenboxcnMHsyNi36OGbKUMVR0WQRCc\" style=\"max-width: 100%; height: auto; max-height: none;\" loading=\"cid:3881ACB5-1580-41CA-8098-38694DB9774E_msgTokenboxcnMHsyNi36OGbKUMVR0WQRCc\"><img data-realheight=\"320\" data-realwidth=\"920\" width=\"474\" src=\"cid:6a880d43-3e11-4f9e-b0d7-1ed8c7dd4bad_msgTokenboxcnPkvwAxHFdjiDRi0YSSalIh\" style=\"max-width: 100%; height: auto; max-height: none;\" loading=\"cid:6a880d43-3e11-4f9e-b0d7-1ed8c7dd4bad_msgTokenboxcnPkvwAxHFdjiDRi0YSSalIh\"></div><div> 顶顶顶顶顶顶顶顶</div><div> 撒发达分的的撒打发灌灌灌灌灌灌灌灌</div><div style=\"white-space:pre-wrap;margin-top:4px;margin-bottom:4px;line-height:1.6\"></div></div></blockquote></div></div></blockquote></div></div></div></div></div></div></div></div></div>"; // result will be an iterator over tuples containing the start and end indices for each match in the string let result = regex.captures_iter(string); for mat in result { println!("{:?}", mat); } }

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 Rust, please visit: https://docs.rs/regex/latest/regex/