JavaScript regular Expressions Getting started notes

Source: Internet
Author: User
Tags regular expression

Two ways to define a regular expression object (REGEXP):

1 var pattern =/s$/;

2 var pattern = new RegExp ("s$");

The system learns two references to regular expressions:

1) Programming Perl by Larry Wall et al. (O ' Reilly).

2) Mastering Regular Expressions by Jeffrey e.f. Friedl (O ' Reilly)

Escape character (backslash): \

Letters and numbers do not need to be escaped. Use the other characters if you can't remember them.

These characters have special meanings that need to be escaped: ^ $. * + ? = ! : | \ / ( ) [ ] { }

Other special character representation methods:

NULL (Unicode hexadecimal notation is \u0000, same below)

\ t Tab (\u0009)

\ newline (\u000a)

\v Vertical tab (\U000B)

\f Form Feed (\u000c)

\ r Carriage return (\u000d)

\xnn the Latin character specified by the hexadecimal number nn; For example, \x0a is the same as \ n

\uxxxx the Unicode character specified by the hexadecimal number xxxx; For example, \u0009 is the same as \ t

\cx the control character ^x; For example, \CJ are equivalent to the newline character \ n

A method of representing a type of character:

[...] Any one of the characters in parentheses

[^...] Any character other than the character in parentheses

. Any character except a newline character (or another Unicode line terminator)

\w letters, numbers, or underscores, equivalent to [a-za-z0-9_]

\w any character except a letter, number, or underscore, equivalent to [^a-za-z0-9_].

\s Unicode whitespace

\s characters other than Unicode whitespace. Be aware that \w and \s are not the same.

\d number, equivalent to [0-9]

\d is not a number, equivalent to [^0-9].

[\b] backspace (the \b between the brackets refers to the character that corresponds to the BACKSPACE key on the keyboard).

\b The position between \w and \w (anchor), note that the second w is uppercase.

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.