Jump to content

Regular Expression


aspnetguy

Recommended Posts

I need a regular expression that will give me the value of href in a <a> tag.This is what I have so far

(<.*?href=(\"|')?|(\"|')?>.*?</a>)

it works if the like is <a href="my url">Link</a> but fails if it is like this <a href="my url" id="mylink">Link</a>so if any other attribute comes after href it is not working and I can'r figure out how to make it work (I am not good at regular expressions).much appreciated.

Link to comment
Share on other sites

Try putting the s modifier on the end of the pattern. That will make it non-greedy, so it will match the minimum amount possible. I think you also need delimiters around the pattern:/(<.*?href=(\"|')?|(\"|')?>.*?</a>)/s

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...