← Back to challenges

RegEx VII-B: Negative Lookbehind

PythonHardlanguage_fundamentalsformattingregex

Instructions

Write a regular expression that will match all the positive numbers in a string with numbers separated by spaces. You must use RegEx negative lookbehind.

txt = "23 -43 34 -44 45 -55 56"
pattern = "yourregularexpressionhere"

re.findall(pattern, txt) ➞ ["23", "34", "45", "56"]

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.