Regular Expressions three - metacharacters

Metacharacters

Metacharacter (Metacharacter) is to have a special meaning of characters:

Metacharacters description
. Find a single character, except for line breaks and line endings.
\w Find a word character.
\W Find a non-word character.
\d Find figures.
\D Finding non-numeric characters.
\s Find a blank character.
\S Find a non-whitespace characters.
\b Find matching located the beginning or end of a word.
\B Find a match not at the beginning or end of a word.
\0 Find NUL characters.
\n Find newline.
\f Find feed character.
\r Find carriage return.
\t Find tab.
\ v Find vertical tab.
\xxx Find octal number xxx defined characters.
\ xdd Find a hexadecimal number dd illegal characters.
\uxxxx Find a hexadecimal number xxxx provisions of Unicode characters.

/ *
* Check whether the string a little.
* Represents any character
* in the regular expression \ represents the escape character
* \. To represent.
* \\ to represent \
* Note
* When using the constructor, because of his parameter is a string, and \ is the escape character
* If you want to use \ you need to use \\ instead!
* /

 

\ W is arbitrary, letters, numbers, _ equivalent to [A-z1-9_]

\ W In addition to letters, numbers, corresponding to _ [^ A-z1-9_]

 

 

 \ D is an arbitrary number corresponding to [0-9]

\ D is in addition to the digital [^ 0-9]

 

 

 \ S is a space meant

\ S in addition to the space

or

 

 

 

 \ B is the meaning of a word boundary

\ B is in addition to the meaning of a word boundary


 A space to accept user input and to remove the front and back of
var str = prompt ( "Please enter your user name")
str = str.replace (/ ^ \ S * | \ * $ S / G, "")

Let no spaces / ^ before the string \ s * /
get behind the string with no spaces / \ s * $ /

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/niuyaomin/p/11610322.html