aspnetguy Posted August 17, 2006 Share Posted August 17, 2006 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 More sharing options...
justsomeguy Posted August 17, 2006 Share Posted August 17, 2006 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 More sharing options...
aspnetguy Posted August 18, 2006 Author Share Posted August 18, 2006 I found this I think it is what I need href[ ]*=[ ]*('|\")([^\"'])*('|\") Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now