A ^ or $ in a regular expression applies only to the first or last alternative, not to all of them
What it finds
A ^ or $ in a regular expression applies only to the first or last alternative, not to all of them
<?php$a = preg_match('/^yes|no|maybe$/', $answer);tx0 reports: ^ applies to one alternative only$b = preg_match('/yes|no$/', $answer);tx0 reports: $ applies to one alternative only$c = preg_match('/^(yes|no)$/', $answer);$d = preg_match('/^yes$|^no$/', $answer);$e = preg_match('/yes|no/', $answer);$f = preg_match('/^\s+|\s+$/', $s);$g = preg_match('/^-|-$|[^-a-z0-9]/', $slug);$j = preg_replace('/^0x|[:\-. ]/i', '', $value);$h = preg_match('/^skel$|_skel$/', $dir);$i = preg_match('/^\.|index\.php/', $file);tx0 reports: ^ applies to one alternative only Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/php:regex-anchor-binds-one-alternative" = "warning"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/php:regex-anchor-binds-one-alternative] reason="..."tx0 explain tx0/php:regex-anchor-binds-one-alternative shows the same in the terminal. Found a false positive? Report it.