← Back to challenges

RegEx VII-A: Negative Lookbehind

PythonHardregexlanguage_fundamentalsformatting

Instructions

Write a regular expression that will help us count how many bad cookies are produced every day. You must use RegEx negative lookbehind.

Example

lst = ["bad cookie", "good cookie", "bad cookie", "good cookie", "good cookie"]
pattern = "yourregularexpressionhere"

len(re.findall(pattern, ", ".join(lst))) ➞ 2

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.