Viewed   98 times

I have full URLs as strings, but I want to remove the http:// at the beginning of the string to display the URL nicely (ex: instead of

Can someone help?


$str = '';
$str = preg_replace('#^https?://#', '', $str);
echo $str; //

That will work for both http:// and https://

Tuesday, August 30, 2022

According to the documentation:

preg_match_all — Perform a global regular expression match

Since you are after just one, you should be using preg_match:

Perform a regular expression match

$regex = '/https?://[^" ]+/i';
$string = "lorem ipsum lorem ipusm dolor";
preg_match($regex, $string, $matches);
echo $matches[0];

Sunday, November 20, 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

This will read in only 1900 and 2000 ranged dates.

Monday, December 5, 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 :