I have one URL field coming from salesforce and i need only href instead of complete URL using amp script.

<a href='https://www.google.com/?hl=en-GB&authuser=1' target='_blank'>Test</a>

i need only href value in one var to solve my issue.

Please help me to solve this issue.

1 Answer 1


You can use regular expression in Ampscript. This will isolate the link from within the a tag in your ampscript variable. You can then use the link within RedirectTo function, allowing you to have it tracked:

SET @text = "<a href=""https://salesforce.stackexchange.com""target=""_blank"">Salesforce</a>"
SET @matching = '<a\s+(?:[^>]*?\s+)?href=(["''])(.*?)\1'
SET @link = RegExMatch(@text, @matching, 2)

<a href="%%=RedirectTo(@link)=%%" target="_blank">Salesforce Stack Exchange</a>
  • Thank you so much its working.
    – hari P
    May 18 at 12:14
  • but while we tried preview and test automatically extra url adding j&utm_source=sfmc&utm_medium=email&utm_campaign=Duplicate+Join&utm_term=%%%3dRedirectTo(%40url1)%3d%%&utm_id=24232&sfmc_id=23816084&campid=
    – hari P
    May 18 at 13:56
  • Could you please help me
    – hari P
    May 18 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.