Viewed   72 times

I'm not familiar with the how regular expressions treat hexadecimal, anyone knows?



The following does the trick:

$str = "some ??????????";

echo preg_replace('/[x{00ff}-x{ffff}]/u', '*', $str);
// some **********

echo preg_replace('/[^x{00ff}-x{ffff}]/u', '*', $str);
// *****??????????

The important thing is the u-modifier (see here):

This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.

And here a short description why uFFFF is not working in PHP:

Perl and PCRE do not support the uFFFF syntax. They use x{FFFF} instead. You can omit leading zeros in the hexadecimal number between the curly braces. Since x by itself is not a valid regex token, x{1234} can never be confused to match x 1234 times. It always matches the Unicode code point U+1234. x{1234}{5678} will try to match code point U+1234 exactly 5678 times.

Tuesday, September 6, 2022

You should use an array of "disallowed" terms and use strpos and str_replace to dynamically remove them from the passed-in URL:

function remove_http($url) {
   $disallowed = array('http://', 'https://');
   foreach($disallowed as $d) {
      if(strpos($url, $d) === 0) {
         return str_replace($d, '', $url);
   return $url;
Thursday, August 25, 2022

The Arabic regex is:


Actually, ?-? is a subset of this Arabic range, so I think you can remove them from the pattern.

So, in JS it will be


See regex demo

Tuesday, October 11, 2022

Use a loop like so

$data = file('website/files/myfolder/file.html');
for ($i = 23; $i <= 116; $i++) {
    echo $data[$i];

Or you could splice the data:

$data = file('website/files/myfolder/file.html');
echo implode(PHP_EOL, array_splice($data, 23, 116 - 23));
Friday, September 23, 2022

For this PHP regex:

$str = preg_replace ( '{(.)1+}', '$1', $str );
$str = preg_replace ( '{[ '-_()]}', '', $str )

In Java:

str = str.replaceAll("(.)\1+", "$1");
str = str.replaceAll("[ '-_\(\)]", "");

I suggest you to provide your input and expected output then you will get better answers on how it can be done in PHP and/or Java.

Sunday, October 9, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :