Regular Expressions Patterns

FinestGladiolus avatar
FinestGladiolus
·
·
Download

Start Quiz

Study Flashcards

10 Questions

What is the purpose of the \b anchor in regular expressions?

To match a word boundary

What is the difference between a capturing group and a non-capturing group in regular expressions?

A capturing group remembers the match, while a non-capturing group does not

What is the purpose of the (?:abc) syntax in regular expressions?

To create a non-capturing group

What does the quantifier a{1,3} match in regular expressions?

Between one and three 'a' characters

What is the purpose of the \W character class in regular expressions?

To match a non-word character

What does the character class [a-g] match in regular expressions?

any character between a and g

What is the purpose of the character in regular expressions?

to match a tab character

What does the regular expression a{2,} match?

two or more a's

What is the purpose of the (?=abc) syntax in regular expressions?

to match abc without including it in the match

What does the regular expression a+?a{2,}? match?

as few a's as possible, followed by two or more a's

Study Notes

Character Classes

  • Any character except newline: \w, \d, \s match word, digit, whitespace respectively
  • Not word, digit, whitespace: \W, \D, \S respectively
  • Match any of a, b, or c: [abc]
  • Not a, b, or c: [^abc]
  • Character between a & g: [a-g]

Anchors

  • Start of the string: ^
  • End of the string: $
  • Word boundary: \b
  • Not-word boundary: \B

Escaped Characters

  • Escaped special characters: \., \\
  • Tab, linefeed, carriage return: \t, \n, \r

Groups & Lookaround

  • Capture group: (abc)
  • Backreference to group #1: \1
  • Non-capturing group: (?:abc)
  • Positive lookahead: (?=abc)
  • Negative lookahead: (?!abc)

Quantifiers & Alternation

  • 0 or more, 1 or more, 0 or 1: a*, a+, a?
  • Exactly five, two or more: a{5}, a{2,}
  • Between one & three: a{1,3}
  • Match as few as possible: a+?, a{2,}?
  • Match ab or cd: ab|cd

Character Classes

  • Any character except newline: \w, \d, \s match word, digit, whitespace respectively
  • Not word, digit, whitespace: \W, \D, \S respectively
  • Match any of a, b, or c: [abc]
  • Not a, b, or c: [^abc]
  • Character between a & g: [a-g]

Anchors

  • Start of the string: ^
  • End of the string: $
  • Word boundary: \b
  • Not-word boundary: \B

Escaped Characters

  • Escaped special characters: \., \\
  • Tab, linefeed, carriage return: \t, \n, \r

Groups & Lookaround

  • Capture group: (abc)
  • Backreference to group #1: \1
  • Non-capturing group: (?:abc)
  • Positive lookahead: (?=abc)
  • Negative lookahead: (?!abc)

Quantifiers & Alternation

  • 0 or more, 1 or more, 0 or 1: a*, a+, a?
  • Exactly five, two or more: a{5}, a{2,}
  • Between one & three: a{1,3}
  • Match as few as possible: a+?, a{2,}?
  • Match ab or cd: ab|cd

Test your understanding of character classes, anchors, and groups in regular expressions. Learn to match patterns and create efficient regex expressions.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Python Regular Expressions Quiz
5 questions

Python Regular Expressions Quiz

AffirmativeTourmaline avatar
AffirmativeTourmaline
Regular Expressions Matching Quiz
12 questions
Java Regular Expressions
18 questions
Use Quizgecko on...
Browser
Browser