Regex JS's regular

Source: Internet
Author: User

1 There are two types of syntax for creating regular expressions:

1. Create a regular with the RegExp regular object:

var regexp=new regexp ("Shen");

2. Create a regular with the literal:

var regexp=/shen/; (regular without quotation marks, matched content also without quotation marks)

2 modifiers

modifier Description
I Performs a match that is not case sensitive.
G Performs a global match (finds all matches rather than stops after the first match is found).
M Performs multi-line matching.

var regexp=/shen/i;

var regexp=new regexp ("Shen", "I");

Square brackets

Square brackets are used to find characters in a range:

An expression Description
[ABC] Look for any characters between square brackets.
[^ABC] Look for any characters that are not in square brackets.
[0-9] Look for any number from 0 to 9.
[A-z] Finds any characters from a to lowercase z from a small write.
[A-z] Look for any characters from uppercase A to uppercase Z.
[A-z] Look for any characters from uppercase A to lowercase z.
[ADGK] Finds any character within a given collection.
[^ADGK] Finds any character outside the given collection.
(Red|blue|green) Finds any of the specified options.
Metacharacters

Metacharacters (metacharacter) is a character that has a special meaning:

Meta character Description
. Finds a single character, in addition to line breaks and line terminators.
\w Find the word character.
\w Finds non-word characters.
\d Find numbers.
\d Finds non-numeric characters.
\s Find white space characters.
\s Finds non-whitespace characters.
\b Matches the word boundary.
\b Matches a non-word boundary.
/ Find NUL characters.
\ n Find line breaks.
\f Find a page break.
\ r Look for the carriage return character.
\ t Find tabs.
\v Find vertical tabs.
\xxx Find the characters that are specified in octal number XXX.
\xdd Finds the characters specified in hexadecimal number DD.
\uxxxx Finds the Unicode characters specified in hexadecimal number xxxx.
Quantifiers
quantifier Description
n+ Matches any string that contains at least one n.
N Matches any string that contains 0 or more N.
N? Matches any string that contains 0 or one n.
N{X} Matches a string that contains a sequence of X N.
N{x,y} Matches a string containing a sequence of X to Y N.
N{x,} Matches a string that contains at least X N of a sequence.
n$ Matches any string that ends with N.
^n Matches any string that begins with N.
? =n Matches any string immediately followed by the specified string n.
?! N Matches any string that does not follow the specified string n immediately thereafter.
RegExp Object Properties
Properties Description FF IE
Global RegExp whether the object has a flag g. 1 4
IgnoreCase RegExp whether the object has a flag I. 1 4
LastIndex An integer that indicates the character position at which to start the next match. 1 4
Multiline RegExp whether the object has a flag m. 1 4
Source The source text of the regular expression. 1 4
RegExp Object Methods
Method Description FF IE
Compile Compiles the regular expression. 1 4
Exec Retrieves the value specified in the string. Returns the found value and determines its location. 1 4
Test Retrieves the value specified in the string. Returns TRUE or FALSE. 1 4
Methods for String objects that support regular expressions
Method Description FF IE
Search Retrieves a value that matches a regular expression. 1 4
Match Finds a match for one or more regular expressions. 1 4
Replace Replace the substring that matches the regular expression. 1 4
Split Splits a string into an array of strings. 1 4

Regex JS's regular

Related Article

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.