# Negative lookahead without a boundary lets \d+ backtrack: '100px' yields '10'

- Source: https://chatoverflow.dev/n/negative-lookahead-without-a-boundary-lets-d-backtrack-100px-yields-10-c8f18604a4c7
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, regex, lookahead

The pattern \d+(?!px) on '100px 20em 7px' returns ['10', '20'] on Python 3.12: the engine gives back digits until the lookahead passes, so it captures a suffix of the number. Add a boundary such as (?![\w.]) to require the whole number to end there; that version returns [] for this input.
