Regex to match html link target

In case you need it. Here is a regular expression that will match lines with hyper links and return link target for them (href attribute value):


If you want to use it from Java here’s how:

private static final Pattern LINK_PATTERN = Pattern.compile("(?:.*\\<[aA][^\\>]*(?i)href(?-i)=\"[^\"]*)([^\"]*)(?:[^\"]*\".*\\</[aA]\\>.*)");
Matcher matcher = LINK_PATTERN.matcher(line);
String href = null;
if (matcher.matches()) {
    //Full match is in group 0 and group 1 is the only captured group
    href =;


8 Responses to Regex to match html link target

  1. Fernando says:

    Hello! Someone in my Myspace group shared this website with us so I came to look
    it over. I’m definitely enjoying the information. I’m book-marking and will be tweeting this to
    my followers! Superb blog and amazing design and style.

  2. Adelaida says:

    Greetings I am so glad I found your blog, I really found you by mistake, while I was researching
    on Aol for something else, Regardless I am here now and would just like to say
    many thanks for a fantastic post and a all round enjoyable blog (I also love the
    theme/design), I don’t have time to go through it all at the minute but I have book-marked it
    and also added your RSS feeds, so when I have time I will be back to read more, Please do keep
    up the great work.

  3. Hello, I want to subscribe for this website to obtain most recent
    updates, so where can i do it please help out.

  4. Princess says:

    What’s up everybody, here every one is sharing these kinds of experience, therefore
    it’s fastidious to read this web site, and I used to pay a visit this blog

  5. Stanton says:

    Encourage aspiring pianists to learn piano using classical Czerny and Burgmuller etudes, or a collection of songs
    from the popular Alfred course books (depending on market area).
    If you decide to use a polish, use one specifically designed for your
    type of piano finish so that it will not harm the finish or the piano
    itself. Then you can start looking at (or listening to,
    as the case may) such other factors as piano tone quality, tuning stability (or life expectancy), action (or piano touch), and piano finish (ie.

  6. Have you ever thought about adding a little bit more than just your articles?

    I mean, what you say is important and everything.
    However think of if you added some great visuals or
    video clips to give your posts more, “pop”! Your content is excellent but with
    pics and videos, this website could definitely be one of the greatest in its niche.
    Good blog!

  7. Hi there, I enjoy reading through your post. I wanted to write a little comment to support

  8. Unquestionably consider that that you stated. Your favourite reason appeared to
    be at the internet the simplest factor to bear in mind of.

    I say to you, I certainly get annoyed even as people consider issues that they plainly
    do not recognise about. You managed to hit the nail upon
    the highest and also outlined out the whole thing with no need side effect , people can take
    a signal. Will probably be again to get more.
    Thank you

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: