hyperlink regular expression pattern

John C johnch_atms at hotmail.com
Fri May 9 06:28:53 PDT 2008


novice2 Wrote:

> > Perhaps someone's got a better pattern they could post?
> 
> this works for me (dmd 1.029)
> 
> import std.regexp;
> 
> void main()
> {
>  if (auto m = std.regexp.search(
>               "<a href=\"www.google.com:8080/dfs?a1=1&a2=2\">This is Google link</a>",
>               "<a[^>]+href=(['\"]?)(.*?)\\1.*?>(.*)</a>"))
>  {
>    for(int i=0; i<10; i++)
>    {
>      printf("%d=\"%.*s\"\n", i, m.match(i));
>    }
>  }
> }
> 

Thanks - that seems to extract the href and text. What about getting other attributes like name and title, as in this link:

<a href=\"www.google.com\" name=\"googleLink\" title=\"Click Me\">Google Link</a>


More information about the Digitalmars-d-learn mailing list