RegEx matching for URLs in HTML

Viewed 92

I currently have this as my command to cut out the URL from a line that starts with href in HTML:

sed -ne 's/.*href="\([^"]*\).*/\1/p'

Since href can start with a ' or " and my command only accounts for " right now, I was wondering how to have that command account for both ' and ".

1 Answers
/^(<)(.*?)(href=)("|')(.*?)(>)$/gm

Demo

or is |.

() helps you to group your string step by step.

It is certainly not the best, but that online tool might help you.

Related