Online Regular Expression Syntax Quick Reference

Regex Character Description
\ Escapes the next character as a special character, a literal character, a back reference, or an octal escape character. For example, "“n" matches the character "n". "\n" matches a newline character. The sequence "\\" matches "\", while "\(" matches "(".
^ Matches the beginning of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after "“\n" or "\r".
$ Matches the end of the input string. If the Multiline property of the RegExp object is set, $ also matches the position before "“\n" or "\r".
* Matches the preceding subexpression zero or more times. For example, "zo*" can match "z" and "zoo". * is equivalent to {0,}.
+ Matches the preceding subexpression one or more times. For example, "“zo+" can match "zo" and "zoo", but not "z". + is equivalent to {1,}.
? Matches the preceding subexpression zero or one time. For example, "“do(es)?" can match "does" or "does" in "do". ? is equivalent to {0,1}.
{n} n is a non-negative integer. Matches exactly n times. For example, "“o{2}" cannot match "Bob"'s "o", but can match two "o"s in "food".
{n,} n is a non-negative integer. Matches at least n times. For example, "“o{2,}" cannot match "Bob"'s "o", but can match all "o"s in "foooood". "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".
{n,m} m and n are non-negative integers, where n <= m. Matches at least n times and at most m times. For example, "“o{1,3}" matches the first three "o"s in "fooooood". "o{0,1}" is equivalent to "o?". Note that there should be no spaces between the comma and the two numbers.
? When this character follows any other quantifier (*, +, ?, {n}, {n,}, {n,m}), the matching mode becomes non-greedy. The non-greedy mode matches as few characters as possible, while the default greedy mode matches as many characters as possible. For example, for the string "“oooo", "o+?" matches a single "o", while "o+" matches all "o"s.
. Matches any single character except "“\n". To match any character, including "\n", use a pattern like "(.|\n)".
(pattern) Matches pattern and captures the match. The captured match can be obtained from the Matches collection, using the SubMatches collection in VBScript or the $0...$9 properties in JScript. To match parentheses characters, use "“\(" or "\)".
(?:pattern) Matches pattern but does not capture the match result. This is a non-capturing match, meaning it's not stored for later use. This is useful when combining various parts of a pattern using the OR character "“(|)". For example, "industr(?:y|ies)" is a more concise expression than "industry|industries".
(?=pattern) Positive lookahead assertion. Matches the search string at the beginning of any string that matches pattern. This is a non-capturing match, meaning it's not stored for later use. For example, "“Windows(?=95|98|NT|2000)" can match "Windows" in "Windows2000", but not in "Windows3.1". The lookahead assertion doesn't consume characters, meaning it starts the next match immediately after the last match, rather than after the characters containing the lookahead.
(?!pattern) Negative lookahead assertion. Matches the search string at any string that does not match pattern. This is a non-capturing match, meaning it's not stored for later use. For example, "“Windows(?!95|98|NT|2000)" can match "Windows" in "Windows3.1", but not in "Windows2000". The lookahead assertion doesn't consume characters, meaning it starts the next match immediately after the last match, rather than after the characters containing the lookahead.
(?<=pattern) Positive lookbehind assertion, similar to positive lookahead but in the opposite direction. For example, "“(?<=95|98|NT|2000)Windows" can match "Windows" in "2000Windows", but not in "3.1Windows".
(?<!pattern) Negative lookbehind assertion, similar to negative lookahead but in the opposite direction. For example, "“(?<!95|98|NT|2000)Windows" can match "Windows" in "3.1Windows", but not in "2000Windows".
x|y Matches x or y. For example, "“z|food" can match "z" or "food". "(z|f)ood" matches "zood" or "food".
[xyz] Character set. Matches any single character contained in the set. For example, "“[abc]" can match "a" in "plain".
[^xyz] Negated character set. Matches any single character not contained in the set. For example, "“[^abc]" can match "p" in "plain".
[a-z] Character range. Matches any single character in the specified range. For example, "“[a-z]" can match any lowercase letter from "a" to "z".
[^a-z] Negated character range. Matches any single character not in the specified range. For example, "“[^a-z]" can match any character not in the range from "a" to "z".
\b Word boundary. Matches a position between a word and a space. For example, "“er\b" can match "er" in "never", but not in "verb".
\B Matches a non-word boundary. "“er\B" can match "er" in "verb", but not in "never".
\cx Matches the control character specified by x. For example, "\cM" matches a Control-M or carriage return. The value of x must be one of A-Z or a-z. Otherwise, treat c as a literal "“c" character.
\d Matches a digit character. Equivalent to [0-9].
\D Matches a non-digit character. Equivalent to [^0-9].
\f Matches a form feed character. Equivalent to \x0c and \cL.
\n Matches a newline character. Equivalent to \x0a and \cJ.
\r Matches a carriage return character. Equivalent to \x0d and \cM.
\s Matches any whitespace character, including space, tab, form feed, etc. Equivalent to [ \f\n\r\t\v].
\S Matches any non-whitespace character. Equivalent to [^ \f\n\r\t\v].
\t Matches a tab character. Equivalent to \x09 and \cI.
\v Matches a vertical tab character. Equivalent to \x0b and \cK.
\w Matches any word character including underscore. Equivalent to “[A-Za-z0-9_]".
\W Matches any non-word character. Equivalent to “[^A-Za-z0-9_]".
\xn Matches the hexadecimal escape value n, where n is a two-digit hexadecimal value. For example, "“\x41" matches "A". "\x041" is equivalent to "\x04&1". ASCII encoding can be used in regular expressions.
\num Matches the numth captured group. For example, "“(.)\1" matches two consecutive identical characters.
\n Identifies an octal escape value or a back reference. If there are at least n capturing groups preceding \n, then \n is a back reference. Otherwise, if \n is an octal digit (0-7), then \n is an octal escape value.
\nm Identifies an octal escape value or a back reference. If there are at least nm capturing groups preceding \nm, then \nm is a back reference. If there are at least n capturing groups preceding \nm, then \n is a back reference followed by the literal character m. If none of the previous conditions are met and n and m are octal digits (0-7), then \nm will match the octal escape value nm.
\nml If n is an octal digit (0-3), and m and l are octal digits (0-7), then matches the octal escape value nml.
\un Matches the Unicode character represented by four hexadecimal digits n. For example, \u00A9 matches the copyright symbol (©).
Username /^[a-z0-9_-]{3,16}$/
Password /^[a-z0-9_-]{6,18}$/
Password2 (?=^.{8,}$)(?=.*\d)(?=.*\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\n).*$ (Consists of digits/uppercase letters/lowercase letters/punctuation marks, all four must be present, at least 8 characters long)
Hexadecimal Value /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
Email Address /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
/^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/ or \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
URL /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ or [a-zA-z]+:\/\/[^\s]*
IP Address /((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)/
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ or ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)
HTML Tags /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/ or <(.*)(.*)>.*<\/\1>|<(.*) \/>
Remove Code\\Comments (?<!http:|\S)//.*$
Match Double-byte Characters (including Chinese characters) [^\x00-\xff]
Chinese Characters (Characters) [\u4e00-\u9fa5]
Chinese Characters Range in Unicode Encoding /^[\u2E80-\u9FFF]+$/
Chinese Characters and Full-width Punctuation Marks (Characters) [\u3000-\u301e\ufe10-\ufe19\ufe30-\ufe44\ufe50-\ufe6b\uff01-\uffee]
Date (Year-Month-Day) (\d{4}|\d{2})-((0?([1-9]))|(1[1|2]))-((0?[1-9])|([12]([1-9]))|(3[0|1]))
Date (Month/Day/Year) ((0?[1-9]{1})|(1[1|2]))/(0?[1-9]|([12][1-9])|(3[0|1]))/(\d{4}|\d{2})
Time (Hour:Minute, 24-hour format) ((1|0?)[0-9]|2[0-3]):([0-5][0-9])
Mainland China Landline Phone Number (\d{4}-|\d{3}-)?(\d{8}|\d{7})
Mainland China Mobile Phone Number 1\d{10}
Mainland China Postal Code [1-9]\d{5}
Mainland China ID Number (15 digits or 18 digits) \d{15}(\d\d[0-9xX])?
Non-negative Integer (Positive Integer or Zero) \d+
Positive Integer [0-9]*[1-9][0-9]*
Negative Integer -[0-9]*[1-9][0-9]*
Integer -?\d+
Decimal (-?\d+)(\.\d+)?
Blank Line \n\s*\r or \n\n (editplus) or ^[\s\S ]*\n
QQ Number [1-9]\d{4,}
Word Without "abc" \b((?!abc)\w)+\b
Matching Leading and Trailing White Spaces ^\s*|\s*$
Common Edits
Here are some replacements for special Chinese characters (editplus)
^[0-9].*\n
^[^第].*\n
^[习题].*\n
^[\s\S ]*\n
^[0-9]*\.
^[\s\S ]*\n
<p[^<>*]>
href="javascript:if\(confirm\('(.*?)'\)\)window\.location='(.*?)'"
<span style=".[^"]*rgb\(255,255,255\)">.[^<>]*</span>
<DIV class=xs0>[\s\S]*?</DIV>

Introduction to Regular Expression Syntax

Our Regular Expression Syntax provides a quick reference for commonly used regular expressions. Whether you need to look up regular expression syntax or understand common regular expression patterns, this resource covers basic syntax, subexpression syntax, modifiers, greedy mode, non-greedy mode, and more, offering a simple and fast way to control strings.

Key features of our Regular Expression Syntax:

  • Commonly Used Regular Expressions: Quick reference for commonly used regular expressions.
  • Regular Expression Syntax Query: Lookup regular expression syntax easily.
  • Basic Syntax: Covers basic syntax elements of regular expressions.
  • Subexpression Syntax: Explains subexpression syntax in regular expressions.
  • Modifiers: Overview of regular expression modifiers.
  • Greedy Mode: Explanation of greedy mode in regular expressions.
  • Non-Greedy Mode: Explanation of non-greedy mode in regular expressions.

Whether you're new to regular expressions or need a quick reference guide, our Regular Expression Syntax resource offers a comprehensive overview and quick lookup tool for mastering regular expressions.

Visit History:

Links: google