JavaScript Classic instances-Regular expressions

Source: Internet
Author: User

1] Regular characters commonly used character

special characters commonly used in regular expressions
Character The Example
^ Start of Match input /^this/matches "This is ..."
$ Match end of input /end$/matches "This is the end"
* Match 0 or more times /se*/matches "Seeee", also matches "se"
? Match 0 or one time /ap?/matches "Apple" and "and"
+ Match one or more times /ap+/matches "Apple" but does not match "and"
N Strictly Match n times /ap{2}/matches "Apple" but does not match "Apie"
{N,} Match n times or N extra times /ap{2,}/matches all p in "apple" and "appple", but does not match "Apie"
{N, m} Matches at least n times, up to M times /ap{2,4}/matches 4 p in "Apppppple"
. Any character other than line break /a.e/matches "ape" and "Axe"
[...] Any of the characters in square brackets /a[px]e/matches "ape" and "axe", but does not match "ale"
[^...] Any character except the character in square brackets /a[px]e/matches ale, but does not match ape, or axe
\b Words on the border \bno\ matches the first "no" in "none"
\b A word on a non-boundary \bno\ matches the second "no" in "none"
\d The number from 0-9 is equivalent to [0-9] /\d{3}/matches "123" in "123"
\d Any non-numeric character is equivalent to [^0-9] /\d{2,4}/matches ' now ' in ' Now ' in 123
\w Match word characters (letters, numbers, underscores) equivalent to [a-za-z0-9_] /\w/matches "J" in JavaScript
\w Match non-word characters (not letters, numbers, underscores) /\w/matches "%" in "100%"
\ n Match a line break
\s A single white-space character
\s A single, non-whitespace character
\ t A tab
(x) Capturing parentheses Remember the characters that match

2] As with other objects, there are direct quantities and regexp of objects.

1 // Regular Objects 2 var New REGEXP ("A\s+b"); 3 // Regular Direct Volume 4 /a\s+b/5// final match a B, or a   B, but does not match AB

(not to be continued ...)

JavaScript Classic instances-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.