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: www.google.com instead of http://www.google.com)
Can someone help?
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: www.google.com instead of http://www.google.com)
Can someone help?
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 http://google.com lorem ipusm dolor http://yahoo.com/something";
preg_match($regex, $string, $matches);
echo $matches[0];
Yields:
http://google.com
The Arabic regex is:
[u0600-u06FF]
Actually, ?-?
is a subset of this Arabic range, so I think you can remove them from the pattern.
So, in JS it will be
/^[a-z0-9+,()/'su0600-u06FF-]+$/i
See regex demo
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.
That will work for both
http://
andhttps://