http://someurlhere.com|http://sometexturl.com|sometexthere
i want to extract only the first url which is before the | , http://someurlhere.com
i have written regular expression
\bhttp(.*)\|\b
but its capture all the occurences of |
Thanx help is appreciated
Make the .* ungreedy : .*?
\bhttp(.*?)\|\b
If you want to match only after the first | do:
\|http://(.*?)\|
with this, the url is in $1
No need for regex. I see you tagged it PHP.
$boom = explode('|', 'http://someurlhere.com|sometexturl.com|sometexthere');
$url = $boom[0];
echo $url;
Output:
http://someurlhere.com
http://codepad.org/xnW0FTfA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With