Regex Flashcards

Study Regex

1
Q

g

A

Global match — find all matches rather than only the first one

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

m

A

Multi-line match — tells the engine to treat the subject string as multiple lines. ^ and $ match next to \n instead of the start or end of the entire string

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

i

A

Ignore case — match both lower and upper case letters

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

.

A

Matches any single character except the newline character. Example: .at matches bat, cat, rat and also .at, 1atEquivalent to [^\x0A\x0D\u2028\u2029]

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

[^…]

A
The negated bracket expression or negated character class matches any single character not contained within the brackets or range of characters. Same as above, except that the ^ negates the expression. Example: [0-9] matches any character that's not a number.Although the ^ character is a special character, it doesn't need to be escaped within the brackets in order to be treated as a literal. Example: [^] matches anything, [^^] matches anything except the ^ character.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

\w

A

Word character| Equivalent to [A-Za-z0-9_]

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

\W

A

Non-word character| Equivalent to [^A-Za-z0-9_]

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

\d

A

Digit character| Equivalent to [0-9]

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

\D

A

Non-digit character| Equivalent to [^0-9]

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

\s

A

Whitespace characterEquivalent to [\f\n\r\t\v\u00A0\u2028\u2029] (\u00A0 means “no-break space”, \u2028 means “line separator”, \u2029 means “paragraph separator”)

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

\S

A

Non-whitespace character| Equivalent to [^\f\n\r\t\v\u00A0\u2028\u2029]

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

\b

A

Word Boundary| Backspace (\x08)

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

\f

A

Form-feed (\x0C)

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

\n

A

Linefeed or newline (\x0A)

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

\r

A

Carriage return (\x0D)

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

\t

A

Tab (\x09)

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

\v

A

Vertical tab (\x0B)

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

\0

A

Null character (\x00)

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

\xhh

A

Character with hexadecimal code hh.

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

\uhhhh

A

Character with hexadecimal code hhhh.

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

[…]

A
The bracket expression specifies a character class and matches any single character contained within the brackets or range of characters. Example: [abc] matches a, b and/or c, in any order.A range of characters is specified using the -, for example [a-z] matches any lowercase ASCII letter from a to z. Other examples include [A-F] which matches any uppercase ASCII letter from A to F, and [4-7] which matches any number from 4 to 7. The - character is treated as a literal character if it's listed first, last or escaped: [-] matches -, [a-] matches a and/or -, [a\-z] matches a, - and/or z.Additionally, listed characters can be mixed with ranges of characters. Example: [0-9a-fA-F] matches any number and also letters from a to z irrespective of their case, [02468aeiouy-] matches even numbers, vowels and the - character.Brackets inside bracket expressions are treated as literals if they are escaped. Example: [\[\]] matches [ and/or ]. The [ doesn't need to be escaped if it's listed first: [[] matches [
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

?

A

Match 0 or 1 times. Example: ab? matches a and ab

23
Q

+

A

Match 1 or more times. Example: ab+ matches ab, abb, abbb etc.

24
Q

{n}

A

Match exactly n times. Example: ab{2} matches abb

25
Q

{n,}

A

Match n or more times. Example: ab{2,} matches abb, abbb, abbbb etc.

26
Q

{n,m}

A

Match at least n times, but no more than m times. Example: ab{2,3} matches abb and abbb

27
Q

??

A

Match 0 or 1 times, but as few times as possible. Example: ab?? against abbbbb matches a

28
Q

*?

A

Match 0 or more times, but as few times as possible. Example: ab*? against abbbbb matches a

29
Q

+?

A

Match 1 or more times, but as few times as possible. Example: ab+? against abbbbb matches ab

30
Q

{n}?

A

Match n or more times, but as few times as possible. Example: ab{2}? against abbbbb matches abb

31
Q

{n,m}?

A

Match at least n times, no more than m times, but as few times as possible. Example: ab{2,3}? against abbbbb matches abb

32
Q

*

A

Match 0 or more times. Example: ab* matches a, ab, abb, abbb etc.

33
Q

(…)

A

Capturing group - group subpattern and capture the match. Example: (foo)bar matches foobar and captures foo

34
Q

…|…

A

Alternation operator - matches one of the alternative subppatterns. Example: foo|bar|baz matches either foo, bar or baz

35
Q

(?:…)

A

Non-capturing group - group subpattern, but don’t capture the match. Example: (?:foo)bar matches foobar and doesn’t capture anything

36
Q

Matches any single character except the newline character.

A

.

37
Q

The bracket expression.

A

[…]

38
Q

The negated bracket expression.

A

[^…]

39
Q

Word character Equivalent to [A-Za-z0-9_]

A

\w

40
Q

Non-word characterEquivalent to [^A-Za-Non-word characterEquivalent to [^A-Za-z0-9_]

A

\W

41
Q

Digit characterEquivalent to [0-9]

A

\d

42
Q

Non-digit characterEquivalent to [^0-9]

A

\D

43
Q

Whitespace characterEquivalent to [\f\n\r\t\v\u00A0\u2028\u2029] (\u00A0 means “no-break space”, \u2028 means “line separator”, \u2029 means “paragraph separator”)

A

\s

44
Q

Non-whitespace characterEquivalent to [^\f\n\r\t\v\u00A0\u2028\u2029]

A

\S

45
Q

Word Boundary| Backspace (\x08)

A

\b

46
Q

Form-feed (\x0C)

A

\f

47
Q

Linefeed or newline (\x0A)

A

\n

48
Q

Carriage return (\x0D)

A

\r

49
Q

Tab (\x09)

A

\t

50
Q

Vertical tab (\x0B)

A

\v

51
Q

Null character (\x00)

A

\0

52
Q

Character with hexadecimal code hh.

A

\xhh

53
Q

Character with hexadecimal code hhhh.

A

\uhhhh