GIAC Python Coder (GPYC) — Question 29
Which python regular expression method should be used to match any character in a-z, 0-9, or !@#$%^&*()?
Answer options
- A. \W
- B. Greedy matching
- C. A custom character set
- D. \w
Correct answer: D
Explanation
The correct answer is D, as the \\w character class matches any alphanumeric character including underscores, which encompasses a-z and 0-9. Option A, \\W, matches non-word characters and is therefore not suitable. Option B, greedy matching, refers to quantifiers and not character matching. Option C, a custom character set, could match these characters but would require more complex syntax.