RegExp Flashcards
Regexp:
Form a regex express to find the year in the string Jan 8, 1998.
\d{4}
\d finds only digits 0-9 and {n} is a quantifier saying how many repetitions to find.
Regexp:
What character is used to declare a regex expression?
/
Regexp:
What is the metacharacter that means the same thing as the quantifier {1,} ?
+
exp+ looks for one or more matches.
Regexp:
What will the expression /(\w)\1/ search for?
2 repeating word characters.
It is similar to /[a-zA-Z0-9]{2}/ only it remembers the searched character in a group.
Regexp:
In the expression /(n|z)it/g what does the g mean?
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.
Regexp:
What does \D search for?
Everything that is not a digit, [^0-9].
Regexp:
regexp.exec(string) is a slightly more powerful version of which string method?
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
Regexp:
Which regexp anchor allows you specify all the non-word characters between words?
\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.
Regexp:
Make a pattern that finds all instances of the for “it” independent of capitalization, where “it” is not part of another word.
/\bit\b/gi