Click here to Skip to main content
15,031,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ive been trying to figure out a RegEx for the following:

<td width="50%" height="19">
<a href="sample_weblink.htm">
Sample Weblink</a></td>
<td width="50%" height="19">

But I can't figure out the RegEx to match only the weblink. In other words I only want to match what's between:

<a href="

Any help would be appreciated.
The regex needs to be Global.


(?<=\<a href\=\")(.+)(?=\")
Sundeepan Sen 23-Sep-10 22:25pm
Thanks! I have tested this with and it works. But when I use it does not work. I am wondering if this will work with C# .NET?
Try non-greedy evaluation, that is, add a ? after the + or *.


class Program


    static void Main(string[] args)
        string strInput = @"
<td width=""50%"" height=""19"">
<a href=""sample_weblink.htm"">
Sample Weblink</a></td>
<td width=""50%"" height=""19"">
        var objMatch = Regex.Match(strInput, @"<a\s+href=[""'](.*?)[""']\s*>");
        if (objMatch.Success)
            Console.WriteLine("Match: {0}", objMatch.Groups[1].Value);

Note: the doubling of the quotes is needed to have embedded quotes in a @"..." string.



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900