A pattern requires a character after $ or before ^, which can never match without multiline mode

tx0/python:regex-unmatchable-anchordefaultwarningreliability/strings-and-regexdepth fastbug

What it finds

Outside multiline mode, $ matches only at the end of the text (or before a final newline) and ^ only at its start, so abc$def and abc^def can never match. The anchor was probably meant to be escaped, as in \$. Patterns with re.MULTILINE or other flags, or with (?m), are left alone.

From the rule's source, regex_unmatchable_anchor.rs.

Example from the rule's tests
import re a = re.search(r"price$5", text)tx0 reports: a character next to this anchor can never be matchedb = re.search(r"price\$5", text)c = re.search(r"a$", text)d = re.search(r"a$\nb", text, re.M)
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/python:regex-unmatchable-anchor" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:regex-unmatchable-anchor] reason="..."

tx0 explain tx0/python:regex-unmatchable-anchor shows the same in the terminal. Found a false positive? Report it.