Regex Flashcards

1
Q

Ruby Regexp

match any character

A

.

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

Ruby Regexp

escape regex special characters

A

\

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

Ruby Regexp

character class delimiter

A

[]

ex, would look to match any 1 of the set [aeiou] [A-Z] [a-z]

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

Ruby Regexp

create a range within a character class

A

-

ex [a-z] [A-Z] [0-9]

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

Ruby Regexp

invert the set of characters in a class, i.e. ‘not’

A

ex [^0-9] [^a-z]

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

Ruby Regexp

anchor that matches the position before the first character of the line

A

\A or ^

in ruby \A matches the start of the entire string, compared to ^ which will match the start of any line

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

Ruby Regexp

anchor that matches the position after the last character of the string

A

\z or $

in ruby \z matches the end of the entire string, compared to $ which will match the end of any line

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

Ruby Regexp

anchor that ensures that the following characters match pattern, but doesn’t include those characters in the matched text

A

(?=pattern)

positive lookahead

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

Ruby Regexp

anchor that ensures that the preceding characters match pattern, but does not include those characters in the matched text

A

(?<=pattern)

positive lookbehind

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

Ruby Regexp

anchor that ensures that the following characters do not match pattern but doesn’t include them in the matched text

A

(?!pattern)

negative lookahead

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

Ruby Regexp

anchor that ensures the preceding characters do not match pattern, but doesn’t include those characters in the matched text

A

(?< !pattern)

negative lookbehind

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

Ruby Regexp

quantifier that makes the previous character optional

A

?

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

Ruby Regexp

quantifier that specifies one or more of the previous character

A

+

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

Ruby Regexp

quantifier that specifies zero or more of the previous character

A

*

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

Ruby Regexp

quantifier that specifies a minimum and maximum number of times the previous character can be repeated

A

{min,max}

ex

{2,4} # 2 to 4 times

{0,1} # same as ?

{1,} # same as +

{0,} # same as *

{3} # exactly 3 times

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

Ruby Regexp

makes a repetition quantifier lazy instead of greedy

A

?

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

Ruby Regexp

sequence that escapes a string of characters, matching them as literal characters

A

\Q…\E

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

Ruby Regexp

alternator symbol in regex

A

|

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

Ruby Regexp

metacharacter matching a position called ‘word boundary’

A

\b

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

Ruby Regexp

subtract one characters class from another

A

[set-[subtract]]

ex [a-z-[aeiou]]

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

Ruby Regexp

with negation and subtraction in a character class, this takes precedence

A

negation

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

Ruby Regexp

used for grouping / capturing part of a regular expression

A

(…)

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

Ruby Regexp

used within parentheses so that a group is not captured

A

?:

ex color=(?:red|green|blue)

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

Ruby Regexp

names a captured group

A

(?< pattern>)

ex

$(?\d+).(?\d+)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
# Ruby Regexp uses a named capture later in the regular expression
\k ex /(?[aeiou]).\k.\k/
26
# Ruby Regexp shorthand for [0-9]
\d
27
# Ruby Regexp shorthand for [A-Za-z0-9]
\w
28
# Ruby Regexp shorthand for [\t\r\n\f]
\s # ex space, a tab, a line break, or a form feed, and others depending on flavor of regex
29
# Ruby Regexp shorthand for [^\d]
\D
30
# Ruby Regexp shorthand for [^\w]
\W
31
# Ruby Regexp shorthand for [^\s]
\S
32
# Ruby Regexp regex delimiter in ruby
/expression/
33
# Ruby Regexp regex method that takes a string as an argument and returns the index of the first match in string
Regexp#=~
34
# Ruby Regexp regex / string method that returns a MatchData object
Regexp#match String#match
35
# Ruby Regexp in a MatchData object, returns the original string that was evaluated
MatchData#string #ex m.string
36
# Ruby Regexp in a MatchData object, returns the substring that matched
MatchData#[0] #ex m[0]
37
# Ruby Regexp in a MatchData object, returns the nth capture
MatchData#[n] #ex m[n]
38
# Ruby Regexp string method that takes a regex as an argument and returns an array of substrings delimited by the regex matches (i.e. discards the matches returning an array of each remaining substring)
String#split
39
# Ruby Regexp string method that takes a regex as an argument and returns an array of all of the matches
String#scan
40
# Ruby Regexp how to use named backreferences with Regexp#=~
Ruby creates local variables with the names and values of each named backreferences
41
# Ruby Regexp end delimiter that causes the expression to ignore case
i ex /pattern/i.match('PATTERN')
42
# Ruby Regexp end delimiter that causes the expression to ignore white space and comments in the pattern
x ex /p a t t e r n/x.match('pattern')
43
# Ruby Regexp global variable equivalent to Regexp::last\_match
$~
44
# Ruby Regexp global variable containing the complete matched text, same as Regexp#[0]
$&
45
# Ruby Regexp global variable containing the string before the match, same as Regexp#pre\_match
$`
46
# Ruby Regexp global variable containing the string after the match, same as Regext#post\_match
$'
47
# Ruby Regexp global variables containing nth capture group, same as Regexp#[n]
$n
48
# Ruby Regexp global variable containing last capture group, same as Regexp#[-1]
$+
49
# Ruby Regexp .
match any character
50
# Ruby Regexp \
escape regex special characters
51
# Ruby Regexp [] ex, would look to match any 1 of the set [aeiou] [A-Z] [a-z]
character class delimiter
52
# Ruby Regexp - ex [a-z] [A-Z] [0-9]
create a range within a character class
53
# Ruby Regexp ^ ex [^0-9] [^a-z]
invert the set of characters in a class, i.e. 'not'
54
# Ruby Regexp \A or ^ in ruby \A matches the start of the entire string, compared to ^ which will match the start of any line
anchor that matches the position before the first character of the line
55
# Ruby Regexp \z or $ in ruby \z matches the end of the entire string, compared to $ which will match the end of any line
anchor that matches the position after the last character of the string
56
# Ruby Regexp (?=pattern) positive lookahead
anchor that ensures that the following characters match `pattern`, but doesn't include those characters in the matched text
57
# Ruby Regexp (?\<=pattern) positive lookbehind
anchor that ensures that the preceding characters match `pattern`, but does not include those characters in the matched text
58
# Ruby Regexp negative lookahead (?!pattern)
anchor that ensures that the following characters do not match `pattern` but doesn't include them in the matched text
59
# Ruby Regexp (?\< !pattern) negative lookbehind
anchor that ensures the preceding characters do not match `pattern`, but doesn't include those characters in the matched text
60
# Ruby Regexp ?
quantifier that makes the previous character optional
61
# Ruby Regexp +
quantifier that specifies one or more of the previous character
62
# Ruby Regexp \*
quantifier that specifies zero or more of the previous character
63
# Ruby Regexp {min,max} ex {2,4} # 2 to 4 times {0,1} # same as ? {1,} # same as + {0,} # same as \* {3} # exactly 3 times
quantifier that specifies a minimum and maximum number of times the previous character can be repeated
64
# Ruby Regexp ?
makes a repetition quantifier lazy instead of greedy
65
# Ruby Regexp \Q...\E
sequence that escapes a string of characters, matching them as literal characters
66
# Ruby Regexp |
alternator symbol in regex
67
# Ruby Regexp \b
metacharacter matching a position called 'word boundary'
68
# Ruby Regexp [set-[subtract]] ex [a-z-[aeiou]]
subtract one characters class from another
69
# Ruby Regexp negation
with negation and subtraction in a character class, this takes precedence
70
# Ruby Regexp (...)
used for grouping / capturing part of a regular expression
71
# Ruby Regexp ?: ex color=(?:red|green|blue)
used within parentheses so that a group is not captured
72
# Ruby Regexp (?\< pattern\>) ex \$(?\d+)\.(?\d+)
names a captured group
73
# Ruby Regexp \k ex /(?[aeiou]).\k.\k/
uses a named capture later in the regular expression
74
# Ruby Regexp \d
shorthand for [0-9]
75
# Ruby Regexp \w
shorthand for [A-Za-z0-9]
76
# Ruby Regexp \s # ex space, a tab, a line break, or a form feed, and others depending on flavor of regex
shorthand for [\t\r\n\f]
77
# Ruby Regexp \D
shorthand for [^\d]
78
# Ruby Regexp \W
shorthand for [^\w]
79
# Ruby Regexp \S
shorthand for [^\s]
80
# Ruby Regexp /expression/
regex delimiter in ruby
81
# Ruby Regexp Regexp#=~
regex method that takes a string as an argument and returns the index of the first match in string
82
# Ruby Regexp Regexp#match String#match
regex / string method that returns a MatchData object
83
# Ruby Regexp MatchData#string #ex m.string
in a MatchData object, returns the original string that was evaluated
84
# Ruby Regexp MatchData#[0] #ex m[0]
in a MatchData object, returns the substring that matched
85
# Ruby Regexp MatchData#[n] #ex m[n]
in a MatchData object, returns the nth capture
86
# Ruby Regexp String#split
string method that takes a regex as an argument and returns an array of substrings delimited by the regex matches (i.e. discards the matches returning an array of each remaining substring)
87
# Ruby Regexp String#scan
string method that takes a regex as an argument and returns an array of all of the matches
88
# Ruby Regexp Ruby creates local variables with the names and values of each named backreferences
how to use named backreferences with Regexp#=~
89
# Ruby Regexp i ex /pattern/i.match('PATTERN')
end delimiter that causes the expression to ignore case
90
# Ruby Regexp x ex /p a t t e r n/x.match('pattern')
end delimiter that causes the expression to ignore white space and comments in the pattern
91
# Ruby Regexp $~
global variable equivalent to Regexp::last\_match
92
# Ruby Regexp $&
global variable containing the complete matched text, same as Regexp#[0]
93
# Ruby Regexp $`
global variable containing the string before the match, same as Regexp#pre\_match
94
# Ruby Regexp $'
global variable containing the string after the match, same as Regext#post\_match
95
# Ruby Regexp $n
global variables containing nth capture group, same as Regexp#[n]
96
# Ruby Regexp $+
global variable containing last capture group, same as Regexp#[-1]