← Back to challenges

RegEx V: Negative Lookahead

PythonHardregexformattingstrings

Instructions

Write a regular expression that will match the states that voted no to President Trump's impeachment. You must use RegEx negative lookahead. You are not allowed to use positive lookaheads.

Example

txt = "Texas = no, California = yes, Florida = yes, Michigan = no"
pattern = "yourregularexpressionhere"

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

Notes

  • You don't need to write a function, just the pattern.
  • Do not remove import re from the code.
  • This is fake data and used only for educational purposes.
  • 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.