Regular Expressions Flashcards

1
Q

What does the regex operator ^ signify?

A

The ^ operator signifies the start of a line or string. It is used to match a pattern only if it appears at the beginning.

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

What does the regex operator $ signify?

A

The $ operator signifies the end of a line or string. It is used to match a pattern only if it appears at the end.

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

What does the regex operator . signify?

A

The . operator matches any single character except a newline. It acts as a wildcard in regex.

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

What does the regex operator * signify?

A

The * operator matches zero or more occurrences of the preceding character or group. For example, a* matches ‘’, ‘a’, ‘aa’, etc.

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

What is the function of the regex operator *?

A

The * operator matches zero or more occurrences of the preceding character or group. It allows for repetition, including none at all.

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

What does the regex operator + signify?

A

The + operator matches one or more occurrences of the preceding character or group. For example, a+ matches ‘a’, ‘aa’, ‘aaa’, etc.

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

What does the regex operator ? signify?

A

The ? operator matches zero or one occurrence of the preceding character or group. For example, colou?r matches both ‘color’ and ‘colour’.

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

What does the regex operator [] signify?

A

Square brackets [] define a character set and match any one character within the set. For example, [abc] matches ‘a’, ‘b’, or ‘c’.

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

What does the regex operator [^ ] do?

A

The [^ ] operator defines a negated character set and matches any character not in the set. For example, [^abc] matches any character except ‘a’, ‘b’, or ‘c’.

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

What does the regex operator | signify?

A

The | operator acts as an OR condition and matches either pattern on its sides. For example, cat|dog matches ‘cat’ or ‘dog’.

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

What does the regex operator () signify?

A

Parentheses () are used for grouping patterns. They allow regex operators to act on the entire group as a unit.

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

What does the regex operator \d signify?

A

The \d operator matches any digit (0–9). It is equivalent to the character set [0-9].

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

What does the regex operator \D signify?

A

The \D operator matches any non-digit character. It is equivalent to the negated set [^0-9].

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

What does the regex operator \w signify?

A

The \w operator matches any word character (alphanumeric and underscore). It is equivalent to [a-zA-Z0-9_].

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

What does the regex operator \W signify?

A

The \W operator matches any non-word character. It is equivalent to the negated set [^a-zA-Z0-9_].

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

What does the regex operator \s signify?

A

The \s operator matches any whitespace character, such as spaces, tabs, or newlines.

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

What does the regex operator \S signify?

A

The \S operator matches any non-whitespace character.

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

What does the regex operator {n} signify?

A

The {n} operator matches exactly ‘n’ occurrences of the preceding character or group. For example, a{3} matches ‘aaa’.

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

What does the regex operator {n,} signify?

A

The {n,} operator matches ‘n’ or more occurrences of the preceding character or group. For example, a{2,} matches ‘aa’, ‘aaa’, etc.

20
Q

What does the regex operator {n,m} signify?

A

The {n,m} operator matches between ‘n’ and ‘m’ occurrences of the preceding character or group. For example, a{2,4} matches ‘aa’, ‘aaa’, or ‘aaaa’.

21
Q

What does the regex operator \ signify?

A

The \ operator escapes special characters, allowing them to be treated as literals. For example, \* matches the ‘*’ character instead of treating it as a regex operator.

22
Q

What does the regex operator \b signify?

A

The \b operator matches a word boundary, ensuring the match occurs at the start or end of a word.

23
Q

What does the regex operator \B signify?

A

The \B operator matches a non-word boundary, ensuring the match occurs within a word.

24
Q

What does the regex operator (?=…) signify?

A

The (?=…) operator is a positive lookahead, ensuring that a certain pattern follows the current position without consuming characters.

25
What does the regex operator (?!...) signify?
The (?!...) operator is a negative lookahead, ensuring that a certain pattern does not follow the current position without consuming characters.
26
What does the regex operator (?<=...) signify?
The (?<=...) operator is a positive lookbehind, ensuring that a certain pattern precedes the current position without consuming characters.
27
What does the regex operator (?
The (?
28
^hello
Matches any string that starts with 'hello'. For example, it will match 'hello world' but not 'a hello world'.
29
.*
Matches zero or more of any character except newline. This can match an empty string, 'abc', or even 'hello123'.
30
\d{3}-\d{2}-\d{4}
Matches a Social Security number format, such as '123-45-6789'. It consists of three digits, a dash, two digits, another dash, and four digits.
31
[A-Za-z]+
Matches one or more uppercase or lowercase letters. For example, it will match 'Hello' and 'abc' but not '123'.
32
colou?r
Matches both 'color' and 'colour'. The '?' means the preceding character 'u' is optional.
33
\bword\b
Matches the word 'word' as a whole word only. It won't match 'sword' or 'wording' but will match 'word'.
34
\d+\.?\d*
Matches integers or decimals. For example, it matches '123', '45.67', or '89.'.
35
(cat|dog)
Matches either 'cat' or 'dog'. The '|' acts as an OR operator between the two options.
36
^[a-z0-9_-]{3,16}$
Matches usernames 3 to 16 characters long, allowing lowercase letters, numbers, underscores, and hyphens. It enforces both the length and allowed characters.
37
\w+@\w+\.\w+
Matches simple email addresses such as 'example@mail.com'. It requires a word, an '@', another word, a '.', and a final word.
38
\s{2,}
Matches two or more whitespace characters in a row. Useful for finding excessive spaces.
39
(?i)hello
Matches 'hello' in a case-insensitive way. It will match 'HELLO', 'hello', or 'HeLLo'.
40
[0-9]{4,}-[A-Z]{2}
Matches a pattern like '1234-AB' where four or more digits are followed by a dash and two uppercase letters.
41
(https?|ftp)://[^\s/$.?#].[^\s]*
Matches URLs that start with 'http', 'https', or 'ftp', such as 'https://example.com'.
42
^.{8,}$
Matches any string that is at least 8 characters long. The '.' matches any character, and '{8,}' enforces the minimum length.
43
^[^@]+@[^@]+\.[a-zA-Z]{2,}$
Matches valid email addresses by ensuring there is no '@' at the start, no '@' immediately before the domain, and the domain has at least two letters.
44
([A-Z][a-z]*){2,}
Matches strings with at least two capitalized words, such as 'JohnDoe' or 'JaneSmith'.
45
([01]?\d|2[0-3]):[0-5]\d
Matches valid 24-hour time formats, such as '23:59', '5:30', or '00:00'.
46
(?<=\$)\d+(\.\d{2})?
Matches monetary values preceded by a '$' symbol, such as '$100' or '$99.99'. It uses a positive lookbehind.
47
^[A-Fa-f0-9]{6}$
Matches valid hexadecimal color codes, such as 'FFAACC' or 'abcdef'.