Py Flashcards

(16 cards)

1
Q

What is the regex pattern to find any three-character sequence where the first character is ‘c’ and the last character is ‘t’?

A

Dot . - Wildcard character
c.t

C, The middle character can be anything, t

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

What test sentence can be used to demonstrate the regex pattern ‘c.t’?

A

I found a cat, a cot, and a cut in the room.

Expected matches: cat, cot, cut

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

What does the dot ‘.’ represent in regex?

A

Any single character (except newline)

It finds sequences where the first and last characters are separated by any character

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

What is the regex pattern to find strings that start with ‘Py’?

A

^Py

The caret ^ ensures that the match must occur at the start of the string or line

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

What test sentence can be used to demonstrate the regex pattern ‘^Py’?

A

Python is fun

Expected matches: [Py] from ‘Python’ at the beginning of the sentence

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

What is the regex pattern to identify strings that end with ‘fun’?

A

fun$

The dollar $ ensures that ‘fun’ is matched only if it’s at the end of the string or line

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

What test sentence can be used to demonstrate the regex pattern ‘fun$’?

A

Learning regex is fun

Expected matches: [fun] from ‘Learning regex is fun’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. What does the asterisk (*) in regex signify?
  2. What about ba*?
A

Zero or more occurrences of the preceding character

Expected Matches: [‘ba’, ‘ba’, ‘b’, ‘baaa’ from ‘bat’, ‘ball’, ‘bed’, & ‘baaah!’

Explanation: The pattern starts with the literal character ‘b’. This means it will first look for occurrences of ‘b’ in the text. Following ‘b’, we have ‘a’. Then the asterisk, which matches 0 or more occurrences of the proceeding character (‘a’ in this case)

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

What is the regex pattern to match a character followed by zero or more ‘a’s?

A

ba*

Example: Matches ‘b’, ‘ba’, ‘baa’, etc.

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

What is the expected match for the regex pattern ‘ba’ in the sentence ‘I saw a bat, and a ball in my bed, baaah!’?

A

ba, ba, b baaal

Matches from ‘bat’, ‘ball’, ‘bed’, and ‘baaah!’.

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

What does the plus sign (+) in regex signify?

A

One or more occurrences of the preceding character

Example: In the pattern ‘ba’, it matches ‘b’ followed by one or more ‘a’s.

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

What is the regex pattern to match a character followed by one or more ‘a’’s in the test sentence:

The battle of ba and baat

A

ba+

Expected Matches: ‘ba’, ‘ba’, ‘baaa’ from ‘battle’, ‘ba’, & ‘baat’

Explanation: The + matches one or more occurrences of the preceding character (‘a’ in this case)

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

What is the expected match for the regex pattern ‘ba’ in the sentence ‘The battle of ba and baat’?

A

ba, baa

Matches from ‘battle’, ‘ba’, and ‘baat’.

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

What does the question mark (?) in regex signify?

A

Zero or one occurrence of the preceding character

Example: Makes a character optional.

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

What is the regex pattern to match both ‘colour’ and ‘color’?

A

colou?r

The ‘u’ is optional in this pattern.

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

What is the expected match for the regex pattern ‘colou?r’ in the sentence ‘The color is nice. I like this colour’?

A

color, colour

Matches both variations in the text.