JavaScript Regular Expressions

Source: Internet
Author: User

/* Regular expression is an object that describes the character pattern.
Regular expressions are used for string pattern matching and retrieval substitution, and are powerful tools for performing pattern matching on strings.

/* Syntax
var patt=new RegExp (pattern,modifiers);
Or in a simpler way:
var patt=/pattern/modifiers;
The modifiers values are as follows:
I perform a match on case insensitive.
G performs a global match (finds all matches rather than stops after the first match is found).
M performs multi-line matching.

For example:
var patt =/aaaa/i;
Alert (Patt.test ("AAAA")); Result is True
var patt2 =/aaaa/;
Alert (Patt2.test ("AAAA")); The result is false


*/
/* Most characters regular in the expression, that is, the literal meaning, such as/a/match a,/b/match b
But there are also characters that have a special meaning in addition to the literal meaning that these characters are meta-characters
In JavaScript, a total of 14 metacharacters (Meta-character)
() [] {} \ ^ $ | ? * + .

Meta-character name matching object
. Dot single arbitrary character (except carriage return \ r, newline \ n, line delimiter \u2028, and segment delimiter \u2029)
A single arbitrary character listed by the [] character group
[^] Excluded character groups are not listed as a single arbitrary character
? Question mark matches 0 or 1 times
* Asterisks match 0-handed or multiple times
+ PLUS sign matches 1 or more times
{Min,max} interval quantifier matches at least min times, max Times
^ The starting position of the caret lines
$ USD Lines End position
| A vertical bar separates any expression on either side
() brackets restrict the range of multi-select structures, the elements that mark the action of quantifiers, and capture text for a reverse reference
\1,\2 ... The reverse reference matches the first, second ... Text that matches an expression within a group of parentheses

* */

JavaScript Regular Expressions

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.