preg_match() is returning inaccurate result
| From: | 0xabeef at riseup dot net | Date: | Tue, 23 Apr 2024 02:24:56 +0000 |
| Subject: | preg_match() is returning inaccurate result | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-328400@lists.php.net to get a copy of this message | ||
PHP8.3.4
Can someone help? preg_match() is acting weird about \$ and \^.
var_dump(preg_match("/\$third-party$/",'xyz$third-party')?true:false);//
returns FALSE, really expecting TRUE here!
var_dump(preg_match("/$third-party$/",'xyz$third-party')?true:false);//
returns TRUE, WHY???
"/^.....\^...\$....$/"
^ and $ must escape if it is not in beginning/ending position.
Isn't this correct?
At least Javascript is answering correctly.
/\$third-party$/.test('xyz$third-party'); // TRUE
/$third-party$/.test('xyz$third-party'); // FALSE