QuestionQ4

Regular Expressions

Which Python regular-expression method should you use to match any character in a-z, 0-9, or !@#$%^&*()?

  • A \W
  • B Greedy matching
  • C A custom character set
  • D \w
Explanation

A custom character set explicitly matches the allowed letters, digits, and punctuation—for example, [a-z0-9!@#$%^&*()]. The \w shorthand excludes those punctuation characters, while \W matches non-word characters rather than the entire specified set.

Community Discussion

No comments yet. Be the first to start the discussion!