JavaScript Regular Expression Two

Source: Internet
Author: User

Predefined classes match common character classes.

Common predefined class characters are:. All characters except carriage return and line break

\d Numeric characters

\d non-numeric characters

\s whitespace characters

\s non-whitespace characters

\w Word characters (such as numbers, letters, and underscores)

\w non-word characters

Regular expressions also provide several commonly used bounds-matching characters, such as: ^ previously started

$ start at the end

\b Word boundaries

\b Non-word boundaries

Non-greedy mode: Let the regular expression match as few as possible, once the match succeeds, no longer matches.

Greedy mode: Let the regular expression match as many matches as possible, matching all matches.

change the non-greedy mode to greedy mode add a question mark after the quantifier, such as: {3,8} ? .

Use () to group, so that quantifiers act on groupings, such as :(my) {3} the words in parentheses are repeated three times.

Use | choose her or him, or the meaning. such as (m|y) select m or y.

reverse references, such as:2017-06-28=>06/28/2017

write ' 2017-06-28 '. Replace (/(\d{4})-(\d{2})-(\d{2})/g, ' $2$3$1 ')

Ignore grouping: Do not want to capture certain groupings, add a question mark within the grouping, such as :(?: my). (OK)

The common quantifiers are:? Occurs 0 or more times (up to one time)

+ occurs one or more times (appears at least once)

* appears 0 or more times (any time)

{N,} appears at least once

{n} appears n times

{N,m} appears n to M times

The regular expression is parsed from the head of the text to the end, and the end of the text is called the front.

The forward-looking is when the regular expression matches the rule and checks forward to see if the assertion is met.

Post-Juniper is in the opposite direction, and JavaScript does not support post-juniper.

Compliant and non-conforming specific assertions are called positive or positive matching and negative or no matching.

Altogether there are: forward-looking exp (? =assert)

Negative forward exp (?! =assert)

Forward Looking back exp (? <=assert)

Negative to looking back exp (? <!assert)

JavaScript Regular Expression Two

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.