Closed as not planned
Description
Bug report
The regular expression I used is working wrongly.
I've made this test file, and found out that the negative sign cannot be searched.
import re
pattern = r"\b(-?\d+)\b"
content = "The temperature is -3 degrees Celsius."
match = re.search(pattern, content)
if match:
number = match.group(1)
print("Found:", number)
else:
print("Not found.")
The result is expected to be "Found: -3", but it turns out to be "Found: 3".
I believe that something is wrong with the "-" in regular expressions.
Your environment
- CPython versions tested on: python-3.11.4-amd64
- Operating system and architecture: Win11 64-bit operating system, x64-based processor
Metadata
Metadata
Assignees
Labels
No labels