RegExp Flashcards

0
Q

Regexp:

Form a regex express to find the year in the string Jan 8, 1998.

A

\d{4}

\d finds only digits 0-9 and {n} is a quantifier saying how many repetitions to find.

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

Regexp:

What character is used to declare a regex expression?

A

/

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

Regexp:

What is the metacharacter that means the same thing as the quantifier {1,} ?

A

+

exp+ looks for one or more matches.

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

Regexp:

What will the expression /(\w)\1/ search for?

A

2 repeating word characters.

It is similar to /[a-zA-Z0-9]{2}/ only it remembers the searched character in a group.

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

Regexp:

In the expression /(n|z)it/g what does the g mean?

A

Global

The expression will find every nit or zit in the string not just the one.

String.match ignores the global flag and only find the first match.

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

Regexp:

What does \D search for?

A

Everything that is not a digit, [^0-9].

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

Regexp:

regexp.exec(string) is a slightly more powerful version of which string method?

A

String.match( )

Regexp.exec is more powerful because the array it returns all the pattern matching information for each match.

  • the matched text
  • the values of the subexpression in parentheses
  • the index of the matched text
  • the original input string
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Regexp:

Which regexp anchor allows you specify all the non-word characters between words?

A

\b

\b or word boundaries match the position between a \w character and a \W character. They value of \b is NOT returned as part of the match.

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

Regexp:

Make a pattern that finds all instances of the for “it” independent of capitalization, where “it” is not part of another word.

A

/\bit\b/gi

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