tags:

views:

359

answers:

2

Hi,

I have many links in my page.

For example <a href="/promotions/download/schools/australia.aspx">Australia</a>

Now I want only the href with its value i.e (href="/promotions/download/schools/australia.aspx") with vbscript regular expression.

+3  A: 

My regex would be something like:

href="([^"]*)"

Might need escaping in your context but that (or something very much like it) should work.

Oli
don't need the brackets if he wants the href= as well. href="[^"]*"
SpliFF
hey guys, I have a variable "sList" which gets dyanmically filled for example <a href="/fddf/dfd/sdfd.aspx">dfd</a>. can you give write sample code from here to get complete href with values in different varaible using vbscript
MKS
Very true, but makes slicing the value out much easier (match group 0 for the whole thing, group 1 for the URI)
Oli
I could copy the code out, but you'd do better to read the whole thing: http://www.regular-expressions.info/vbscript.html
Oli
hi Oli, can you please write sample code for this
MKS
I just gave you one. Go to the link above and skip to the How to Use the VBScript RegExp Object section.
Oli
A: 

Regexes are fundamentally bad at parsing HTML (see Can you provide some examples of why it is hard to parse XML and HTML with a regex? for why). Luckily, you should have access to the best parser available: the web browser. Modern browsers create a Document Object Model which is a tree structure that contains all of the information about the page. One of the methods you can call on the DOM is links. I don't really know vbscript, but this code looks like it should work:

For i = 0 To document.links.length
  document.write(document.links(i).href & "<BR>")
Next
Chas. Owens