Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract url from a string with regex in shell script

I need to extract a URL that is wrapped with <strong> tags. It's a simple regular expression, but I don't know how to do that in shell script. Here is example:

line="<strong>http://www.example.com/index.php</strong>"
url=$(echo $line | sed -n '/strong>(http:\/\/.+)<\/strong/p')

I need "http://www.example.com/index.php" in the $url variable.

Using busybox.

like image 341
Serge Avatar asked Jul 14 '26 18:07

Serge


1 Answers

This might work:

url=$(echo $line | sed -r 's/<strong>([^<]+)<\/strong>/\1/')
like image 119
Sicco Avatar answered Jul 17 '26 15:07

Sicco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!