I have the following Regex to match all link tags on a page generated from our custom cms
<a\s+((?:(?:\w+\s*=\s*)(?:\w+|"[^"]*"|'[^']*'))*?\s*href\s*=\s*(?<url>\w+|"[^"]*"|'[^']*')(?:(?:\s+\w+\s*=\s*)(?:\w+|"[^"]*"|'[^']*'))*?)>.+?</a>
We are using c# to loop through all matches of this and add an onclick event to each link (for tracking software) before rendering the page content. I need to parse the link and add a parameter to the onclick function which is the "link name".
I was going to modify the regex to get the following subgroups
- The title attribute of the link
- If the link contains an image tag get the alt text of the image
- The text of the link
I can then check the match of each subgroup to aqquire the relevant name of the link.
How would I modify the above regex to do this or could I achieve the same think using c# code?