Regex Flashcards

You may prefer our related Brainscape-certified 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
Q

Ruby Regexp

uses a named capture later in the regular expression

A

\k

ex

/(?[aeiou]).\k.\k/

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

Ruby Regexp

shorthand for [0-9]

A

\d

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

Ruby Regexp

shorthand for [A-Za-z0-9]

A

\w

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

Ruby Regexp

shorthand for [\t\r\n\f]

A

\s # ex space, a tab, a line break, or a form feed, and others depending on flavor of regex

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

Ruby Regexp

shorthand for [^\d]

A

\D

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

Ruby Regexp

shorthand for [^\w]

A

\W

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

Ruby Regexp

shorthand for [^\s]

A

\S

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

Ruby Regexp

regex delimiter in ruby

A

/expression/

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

Ruby Regexp

regex method that takes a string as an argument and returns the index of the first match in string

A

Regexp#=~

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

Ruby Regexp

regex / string method that returns a MatchData object

A

Regexp#match

String#match

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

Ruby Regexp

in a MatchData object, returns the original string that was evaluated

A

ex

MatchData#string

m.string

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

Ruby Regexp

in a MatchData object, returns the substring that matched

A

ex

MatchData#[0]

m[0]

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

Ruby Regexp

in a MatchData object, returns the nth capture

A

ex

MatchData#[n]

m[n]

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

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)

A

String#split

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

Ruby Regexp

string method that takes a regex as an argument and returns an array of all of the matches

A

String#scan

40
Q

Ruby Regexp

how to use named backreferences with Regexp#=~

A

Ruby creates local variables with the names and values of each named backreferences

41
Q

Ruby Regexp

end delimiter that causes the expression to ignore case

A

i

ex

/pattern/i.match(‘PATTERN’)

42
Q

Ruby Regexp

end delimiter that causes the expression to ignore white space and comments in the pattern

A

x

ex

/p a t t e r n/x.match(‘pattern’)

43
Q

Ruby Regexp

global variable equivalent to Regexp::last_match

A

$~

44
Q

Ruby Regexp

global variable containing the complete matched text, same as Regexp#[0]

A

$&

45
Q

Ruby Regexp

global variable containing the string before the match, same as Regexp#pre_match

A

$`

46
Q

Ruby Regexp

global variable containing the string after the match, same as Regext#post_match

A

$’

47
Q

Ruby Regexp

global variables containing nth capture group, same as Regexp#[n]

A

$n

48
Q

Ruby Regexp

global variable containing last capture group, same as Regexp#[-1]

A

$+

49
Q

Ruby Regexp

.

A

match any character

50
Q

Ruby Regexp

\

A

escape regex special characters

51
Q

Ruby Regexp

[]

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

A

character class delimiter

52
Q

Ruby Regexp

-

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

A

create a range within a character class

53
Q

Ruby Regexp

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

A

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

54
Q

Ruby Regexp

\A or ^

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

A

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

55
Q

Ruby Regexp

\z or $

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

A

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

56
Q

Ruby Regexp

(?=pattern)

positive lookahead

A

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

57
Q

Ruby Regexp

(?<=pattern)

positive lookbehind

A

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

58
Q

Ruby Regexp

negative lookahead (?!pattern)

A

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

59
Q

Ruby Regexp

(?< !pattern)

negative lookbehind

A

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

60
Q

Ruby Regexp

?

A

quantifier that makes the previous character optional

61
Q

Ruby Regexp

+

A

quantifier that specifies one or more of the previous character

62
Q

Ruby Regexp

*

A

quantifier that specifies zero or more of the previous character

63
Q

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

A

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

64
Q

Ruby Regexp

?

A

makes a repetition quantifier lazy instead of greedy

65
Q

Ruby Regexp

\Q…\E

A

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

66
Q

Ruby Regexp

|

A

alternator symbol in regex

67
Q

Ruby Regexp

\b

A

metacharacter matching a position called ‘word boundary’

68
Q

Ruby Regexp

[set-[subtract]]

ex [a-z-[aeiou]]

A

subtract one characters class from another

69
Q

Ruby Regexp

negation

A

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

70
Q

Ruby Regexp

(…)

A

used for grouping / capturing part of a regular expression

71
Q

Ruby Regexp

?:

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

A

used within parentheses so that a group is not captured

72
Q

Ruby Regexp

(?< pattern>)

ex

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

A

names a captured group

73
Q

Ruby Regexp

\k

ex

/(?[aeiou]).\k.\k/

A

uses a named capture later in the regular expression

74
Q

Ruby Regexp

\d

A

shorthand for [0-9]

75
Q

Ruby Regexp

\w

A

shorthand for [A-Za-z0-9]

76
Q

Ruby Regexp

\s # ex space, a tab, a line break, or a form feed, and others depending on flavor of regex

A

shorthand for [\t\r\n\f]

77
Q

Ruby Regexp

\D

A

shorthand for [^\d]

78
Q

Ruby Regexp

\W

A

shorthand for [^\w]

79
Q

Ruby Regexp

\S

A

shorthand for [^\s]

80
Q

Ruby Regexp

/expression/

A

regex delimiter in ruby

81
Q

Ruby Regexp

Regexp#=~

A

regex method that takes a string as an argument and returns the index of the first match in string

82
Q

Ruby Regexp

Regexp#match

String#match

A

regex / string method that returns a MatchData object

83
Q

Ruby Regexp

MatchData#string

m.string

A

in a MatchData object, returns the original string that was evaluated

84
Q

Ruby Regexp

MatchData#[0]

m[0]

A

in a MatchData object, returns the substring that matched

85
Q

Ruby Regexp

MatchData#[n]

m[n]

A

in a MatchData object, returns the nth capture

86
Q

Ruby Regexp

String#split

A

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
Q

Ruby Regexp

String#scan

A

string method that takes a regex as an argument and returns an array of all of the matches

88
Q

Ruby Regexp

Ruby creates local variables with the names and values of each named backreferences

A

how to use named backreferences with Regexp#=~

89
Q

Ruby Regexp

i

ex

/pattern/i.match(‘PATTERN’)

A

end delimiter that causes the expression to ignore case

90
Q

Ruby Regexp

x

ex

/p a t t e r n/x.match(‘pattern’)

A

end delimiter that causes the expression to ignore white space and comments in the pattern

91
Q

Ruby Regexp

$~

A

global variable equivalent to Regexp::last_match

92
Q

Ruby Regexp

$&

A

global variable containing the complete matched text, same as Regexp#[0]

93
Q

Ruby Regexp

$`

A

global variable containing the string before the match, same as Regexp#pre_match

94
Q

Ruby Regexp

$’

A

global variable containing the string after the match, same as Regext#post_match

95
Q

Ruby Regexp

$n

A

global variables containing nth capture group, same as Regexp#[n]

96
Q

Ruby Regexp

$+

A

global variable containing last capture group, same as Regexp#[-1]