Finding a Regex binary pattern in PHP

I am trying to find and replace binary values โ€‹โ€‹in strings:

$str = '('.chr(0x00).chr(0x91).')' ;
$str = preg_replace("/\x00\x09/",'-',$str) ;

But I get a "Warning: preg_replace (): Zero byte in the regex message .

How to work with binary values โ€‹โ€‹in Regex / PHP?

+4
source share
1 answer

This is because you use double quotes "around your regular expression pattern, which cause the php engine to parse \x00and characters \x09.

If you use single quotes, this will work:

$str = '(' . chr(0x00) . chr(0x91) . ')' ;
$str = preg_replace('/\x00\x09/', '-', $str) ;

, . \x00 \x91 -, []:

$str = preg_replace('/[\x00\x91/]', '-', $str) ;
+7

Source: https://habr.com/ru/post/1655246/


All Articles