Metacharacters Flashcards
What does .
metacharacter match?
any single character except for a newline character “(\n)”
What does +
metacharacter match?
one or more occurrences of the preceding character or group
Which symbol denotes the start of a line or string?
^
What does \w
match?
- any word character, which includes alphanumeric characters (letters and digits) as well as underscores
_
- equivalent to the character class
[A-Za-z0-9_]
What does \s
match?
any whitespace character, which includes spaces, tabs, and newline characters
What does \D
match?
any character that is not a digit - negation of \d
What does \d
match?
any digit, which is equivalent to the character class [0-9]
; represents a single numeric digit from 0 to 9
What is the role of parentheses ()
in regular expressions?
primarily used for grouping, capturing, and controlling the precedence of subpatterns within a larger pattern
How are parentheses ()
used for grouping?
- useful when there is a need to apply a quantifier
(e.g., *, +, ?, {})
to a specific group of characters - helps to ensure that all grouped elements are treated as a single unit within a pattern
(abc){2}
What are word characters?
includes [A-Za-z0-9_]
What does \w+
mean?
one or more characters are being matched
What does .*
match?
any character (except newlines) zero or more times