RegExp Flashcards

1
Q

哪两种方法可以创建RegExp?

A

/pattern/flags;new RegExp(pattern [, flags]);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

有哪些flags?

A

gglobal matchiignore casemmultiline; treat beginning and end characters (^ and $) as working over multiple lines (i.e., match the beginning or end of each line (delimited by \n or \r), not only the very beginning or end of the whole input string)ysticky; matches only from the index indicated by the lastIndex property of this regular expression in the target string (and does not attempt to match from any later indexes). This allows the match-only-at-start capabilities of the character “^” to effectively be used at any location in a string by changing the value of the lastIndex property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

matches any single character except the newline characters: \n \r \u2028 or \u2029.

A

.For example, /.y/ matches “my” and “ay”, but not “yes”, in “yes make my day”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Matches a digit character in the basic Latin alphabet. Equivalent to [0-9].

A

\dFor example, /\d/ or /[0-9]/ matches ‘2’ in “B2 is the suite number.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Matches any character that is not a digit in the basic Latin alphabet. Equivalent to [^0-9].

A

\DFor example, /\D/ or /[^0-9]/ matches ‘B’ in “B2 is the suite number.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Matches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to [A-Za-z0-9_].

A

\wFor example, /\w/ matches ‘a’ in “apple,” ‘5’ in “$5.28,” and ‘3’ in “3D.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Matches any character that is not a word character from the basic Latin alphabet. Equivalent to [^A-Za-z0-9_].

A

\WFor example, /\W/ or /[^A-Za-z0-9_]/ matches ‘%’ in “50%.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Matches a single white space character, including space, tab, form feed, line feed and other unicode spaces. Equivalent to [ \t\r\n].

A

\sFor example, /\s\w*/ matches ‘ bar’ in “foo bar.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Matches a single character other than white space (Not whitespace). Equivalent to [^ \t\r\n].

A

\SFor example, /\S\w*/ matches ‘foo’ in “foo bar.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Matches a tab.

A

\t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Matches a carriage return.

A

\r

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Matches a linefeed.

A

\n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Matches a backspace.

A

[\b] (Not to be confused with \b)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Where X is a letter from A - Z. Matches a control character in a string.

A

\cXFor example, /\cM/ matches control-M in a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

将开头的字母与空格后的字母替换为大写。

A

(^|\s) ([a-z])String.prototype.capitalize = function(){ return this.replace( /(^|\s)([a-z])/g, function(m, p1, p2) { return p1+p2.toUpperCase(); });}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly