RegExps Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

what two literals are used to create reflexes?

A

/…/ and %r{…}

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

What is the basic pattern matching operator

A

=~

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

Which method returns a MatchData object?

A

match( )

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

How would you write an expression to return a match of “st” in “haystack”?

A
/st/.match('haystack')
# ==> #
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 10 metacharacters?

A

(, ), [, ], {, }, ., ?, +, *

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

What do character classes represent ??

A

They list characters that may appear at a certain point in the match.

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

Within a character class, what metacharacter denotes an inclusive range of characters?

A

[a-z][0-9]

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

How do you invert a character match?

A

Use the ^ (caret) before the character

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

What does inverting the character match do?

A

It matches any character except the one inverted

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

How can you set an intersection of character classes?

A

/[a-w]&&[^c-g]z]/

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

Any character except a newline

A

/./

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

Any character

A

/./m (m enables multiline mode)

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

A word character

A

/\w/ ([a-zA-Z0-9_])

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

a NON word character

A

/\W/ ([^a-zA-Z0-9_])

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

A digit character

A

/\d/ ( [0-9] )

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

A NON digit character

A

/\D/ ( [^0-9] )

17
Q

A hexdigit character

A

([0-9a-fA-F])

18
Q

A NON hexdigit character

A

([^0-9a-fA-F])

19
Q

A whitespace character

A

/ [ \t\r\n\f\v ]/

20
Q

A NON whitespace character

A

/ [^ \t\r\n\f\v ]/