JS Regular expression

Source: Internet
Author: User
Tags control characters net regex

/^[a-za-z\u4e00-\u9fff]*$/can only input Chinese and English
/^[\u4e00-\u9fff\w\s ((#))]*$/Kanji alphanumeric underline empty Gaki bracket
/^[1-9]\D{4,11}$/QQ number

. match any character except line break
\w match letters or numbers or underscores or kanji
\s matches any whitespace character
\d Matching numbers
\b Match the beginning or end of a word
^ Start of matching string
$ match End of string
* Repeat 0 or more times
+ Repeat one or more times
? Repeat 0 or one time
{n} repeats n times
{n,} repeats n or more times
{N,m} repeats n to M times
\w matches any characters that are not letters, numbers, underscores, kanji
\s matches any character that is not a white letter
\d matches any non-numeric character
\b Match is not where the word starts or ends
[^x] matches any character except X
[^aeiou] matches any character except the letters AEIOU
* Repeat any number of times, but repeat as little as possible
+ repeat 1 or more times, but repeat as little as possible
?? Repeat 0 or 1 times, but repeat as little as possible
{n,m}? Repeat N to M times, but as few repetitions as possible
{n,}? Repeat more than n times, but repeat as little as possible

Capture (exp) matches exp, and captures text into an automatically named group
(? <name>exp) matches exp, and captures the text into a group named name, which can also be written as (? ' Name ' exp ')
(?: EXP) matches exp, does not capture matching text, and does not assign group numbers to this group
0 Wide assertion (? =exp) matches the position of the exp front
(? <=exp) matches the position after exp
(?! EXP) match the location followed by the EXP
(? <!exp) matches a position that is not previously exp
Note (? #comment) This type of grouping does not have any effect on the processing of regular expressions and is used to provide comments that let people read

\s+ matches a string that does not contain whitespace characters
<a[^>]+> match a string preceded by a with angle brackets
(? <= # asserts the prefix of the text to match
< (\w+) > # Find letters or numbers enclosed in angle brackets (i.e. html/xml tags)
) # prefix end
. * # matches any text
(? = # to assert the suffix of the text to match
<\/\1> # Find the content enclosed in angle brackets: preceded by a "/", followed by a previously captured label
) # suffix End
\a Alarm character (the effect of printing it is the computer beeps)
\b is usually the word dividing position, but if you use a delegate backspace in a character class
\ t tab, tab
\ r Enter
\v Vertical Tab
\f Page Break
\ n line break
\eescape
\0nnascii code with octal code as nn character
Characters in \xnnascii code with hexadecimal code NN
Characters with hexadecimal code nnnn in \unnnnunicode code
\cnascii control characters. For example, \CC represents CTRL + C
\a the beginning of a string (similar to ^, but not affected by the processing of multiline options)
\z end of string or end of line (not affected by multi-line processing options)
\z the end of a string (similar to $, but not affected by the processing of multiline options)
\g the beginning of the current search
Character class named name in \p{name}unicode, for example \p{isgreek}
(? >exp) Greedy sub-expression
(? <x>-<y>exp) Balance Group
Change processing options in sub-expression exp (? im-nsx:exp)
(? im-nsx) changes the processing options for the part after the expression
(? (exp) yes|no) The exp as a 0-wide forward assertion, if this position can match, use Yes as the expression of this group;
(? (exp) Yes) Ditto, just use an empty expression as no
(? (name) yes|no) if the group named name captures content, use Yes as the expression;
(? (name) Yes), just use an empty expression as no
The Regexp.test () method in JavaScript or. NET Regex.IsMatch () method. The match here refers to the part of the string that does not conform to the expression rule egex regex = new Regex (@ "\ba\w{6}\b", regexoptions.ignorecase);
IgnoreCase (ignoring case) matches are case-insensitive.
Multiline (multiline mode) changes the meaning of ^ and $ so that they match at the beginning and end of each line, not just at the beginning and ending of the entire string. (In this mode, the exact meaning of $ is: match the position before \ n and the position before the end of the string.)
Singleline (single-line mode) changes the meaning of it to match each character (including the newline character \ n).
Ignorepatternwhitespace (ignore whitespace) ignores non-escaped whitespace in an expression and enables comments marked by #.
Explicitcapture (Explicit capture) captures only groups that have been explicitly named.

I

JS Regular expression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.