← Back to challenges

RegEx XVI: Negation

PythonHardregexstrings

Instructions

The caret ^, when found at the start of a character set, is the equivalent to "not" in RegEx. The regular expression [^a-c] matches any characters except "a", "b" and "c". Write the regular expression that matches any characters except letters, digits and spaces. You must use a negated character set in your expression.

Examples

txt = " [email protected] "
pattern = "yourregularexpressionhere"

re.findall(pattern, txt) ➞ ["@", "."]

Notes

  • You don't need to write a function, just the pattern.
  • Do not remove import re from the code.
  • You can find all the challenges of this series in my Basic RegEx collection.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Invert Keys and Values