blue-sky
blue-sky

Reputation: 53806

Match href and 'a' value in link

How can I match the href and 'a' vlaue in a link ?

So extract 'www.google.com' & 'test' from below :

<A HREF="www.google.com/test.html" title="test">test</A>

Here is what I am trying : '<A HREF=(.+).html' but it is not matching ?

Upvotes: 1

Views: 84

Answers (3)

Joachim Isaksson
Joachim Isaksson

Reputation: 180897

Regular expressions for HTML can be brittle to change, but a regex for this exact case would be;

<A HREF="\(.*\)" .*>\(.*\)</A>

Upvotes: 1

prageeth
prageeth

Reputation: 7395

Try this:

<A.*HREF\s*=\s*(?:"|')([^"']*)(?:"|').*>(.*)<\/A>

Group1 and Group2 will give you the desired result.

Upvotes: 1

paddy
paddy

Reputation: 63471

Because the text html does not appear in your tag.....

Upvotes: 0

Related Questions