0

In Data Extension one field 'HTML' have Data that I have shown below, Now I have to Find the 'Href', and and at the last of URL append some text like '&MC='. It may have Multiple 'Href'. Please help me on this.

<table width="540" style="margin: 0px; padding: 0px;" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0">
 <tbody>
  <tr>
   <td valign="top">
   <h5 style="margin: 0px; padding: 0px 0px 2px; line-height: normal; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 16px; font-weight: normal;">
   <a style="text-decoration: none;" href="https://test.4.com/testRegistration/testLobbyServlet?target=reg20.jsp&eventid=897605&sessionid=1&key=2F3D1EB963D9DB7738BF2877DFFDBA01&partnerref=Social&sourcepage=register&loc=zOTlocz&prod=zWAz&tech=zsecz&prog=zOTprogz&type=zOTtypez&media=zWCz&country=zUSz" alias="Success with Enterprise Mobility: Making email and Office 365 secure on mobile devices">
   Success with Enterprise Mobility: Making email and Office 365 secure on mobile devices 
   </a>
   </h5>
   <p style="margin: 0px; padding: 0px; line-height: 20px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal;">
   <span style="color: rgb(103, 103, 103);">
   <em>December 9, 2014, 10:30 A.M.&ndash;11:30 A.M. Pacific Time</em><br>
   An enterprise mobility strategy involves identity, management, and productivity. In this session featuring Brad Anderson, you will learn about the integration and the Office mobile apps while enabling secure mobile productivity.
   </span>
   </p>
   </td>
  </tr>
  <tr>
   <td valign="top">&nbsp;
   </td>
  </tr>
  <tr>
   <td valign="top">
   <h5 style="margin: 0px; padding: 0px 0px 2px; line-height: normal; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 16px; font-weight: normal;">
   <a style="text-decoration: none;" href="http://test.TTr.com/?Wt.mc_id=IG15W2NWTN&loc=zOTlocz&prod=zWAz&prod=zWSz&tech=zCLz&prog=zOTprogz&type=zEVz&media=zOTmediaz&country=zUSz" alias="Test: Everything about enterprise technology under one roof">
   Test: Everything about enterprise technology under one roof
   </a>
   </h5>
   <p style="margin: 0px; padding: 0px; line-height: 20px; font-family: &quot;Segoe UI&quot;, &quot;Lucida Grande&quot;, Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal;">
   <span style="color: rgb(103, 103, 103);">
   <em>May 4&ndash;8, 2015, Chicago, IL</em><br>
   If you&rsquo;re serious about technology, you don&rsquo;t want to miss Test. This event will be the intersection of everything in enterprise technology. Get ahead in your job and your career.
   </span>
   </p>
   </td>
  </tr>
 </tbody>
</table> 
5
  • HTML Field have data like this "href=blogs.xxyz.com/b/dotnet/archive/2014/12/04/…" and result should like this blogs.xxyz.com/b/dotnet/archive/2014/12/04/…
    – SFMC_User
    Commented Jun 2, 2015 at 1:39
  • please update your question with the additional comment. Putting it in a comment makes it difficult to understand what you need exactly. Commented Jun 2, 2015 at 7:34
  • Please post the AMPScript code that you have so far. Commented Jun 2, 2015 at 13:30
  • @adam I posted the code...but I am new to this So code didn't come in proper format.
    – SFMC_User
    Commented Jun 2, 2015 at 20:29
  • Thanks @AdamSpriggs, In sourceStr I have HTML Data that[that have multiple URL] But My code takes just First one...
    – SFMC_User
    Commented Jun 2, 2015 at 20:37

2 Answers 2

1

You'll need to iterate through the entire string. I'd suggest utilizing the BuildRowSetFromString() function. Something like this:

%%[
var @t, @rs, @rc
set @t = 'some text, then a <a href="http://someurl.com?p=1" alias="link1">link1</a>. some more text and <a alias="link2" href="http://someurl.com?p=2">link2</a> and more text'
set @t = replace(replace(@t,"<","&lt;"),">","&gt;")
set @rs = buildrowsetfromstring(@t," ")
set @rc = rowcount(@rs)

set @newParm = "&n=1"

outputline(concat("<p><b>original</b></p>",@t))

set @t2 = ""

/* iterate through rowset of words */
for @i = 1 to @rc do

  set @r = row(@rs, @i)
  set @s = field(@r,1)

  set @s2 = @s

  /* of the word starts with href */
  if indexOf(@s,"href") > 0 then

     set @qc = 0

     /* iterate through each character */
     for @j = 1 to length(@s) do

       /* if you encounter a double quote... */
       if substring(@s,@j,1) == '"' then
         set @qc = add(@qc,1)

         /* if it's the second one, insert the new parameter */
         if @qc == 2 then
           set @first = substring(@s,1,subtract(@j,1))
           set @last = substring(@s,@j,length(@s))
           set @s2 = concat(@first,@newParm,@last)
         endif

       endif

     next @j

  endif
  /* concatenate new string, word by word */
  set @t2 = concat(@t2, " ",@s2)

next @i


outputline(concat("<p><b>new</b></p>",@t2))

set @t2 = replace(replace(@t2,"&lt;","<"),"&gt;",">")

]%%
3
  • "set @t = replace(replace(@t,"<","&lt;"),">","&gt;")" this code replacing HTML code in text??? and one this what will put if in URL doesn't have '?' first it should track '?' then only we have to add '&test' otherwise '?test'....Please guide me on this..
    – SFMC_User
    Commented Jun 2, 2015 at 21:35
  • I encode the < and > at the beginning in order to utilize the buildrowsetfromstring() function.. then do the reverse at the end. The function won't parse properly if you don't do that part. Commented Jun 2, 2015 at 21:37
  • I'll leave the handling of the & vs ? to you. Commented Jun 2, 2015 at 21:39
0
%%[
VAR @sourceStr

SET @sourceStr = 'str'

SET @regEx1 = '.*(href="[a-zA-Z0-9:/&=?.$-_#]+).*'
SET @append = "&MC=HTML5"
VAR @result
SET @result = RegExMatch(@sourceStr, @regEx1, 0, "IgnoreCase", "Multiline")
SET @TaggedUTL= Concat(RegExMatch(@sourceStr, @regEx1, 1),@append)

IF Length(@result) > 0 THEN
    SET @outPut = Replace(@sourceStr,RegExMatch(@sourceStr, @regEx1,1), @TaggedUTL) /*It takes only first URL*/
ENDIF 

]%%
Replaced:  %%=v(@outPut)=%%<br>
5
  • In SET @sourceStr='HTML Data' where have some URL LIke (Xxyz.com/…) and [Link] (XXyz.com/…) with href= but my code just take first URL...Please Help on this
    – SFMC_User
    Commented Jun 2, 2015 at 20:12
  • you probably don't want to use a regex to parse html Commented Jun 2, 2015 at 20:16
  • @charles Actually My HTML code that is inside the DE field... here I am trying to find the 'Href=' then I have to Append some text at the last of URL then Whole HTML thing will come up with that.....But here I am successfully getting only one 'Href=' not others.....
    – SFMC_User
    Commented Jun 2, 2015 at 20:25
  • what happens if someone is writing an email about how to write html, so href="http://google.com" is part of the text? Commented Jun 2, 2015 at 20:51
  • @charles it will never be... adam have give me fine solution on this.
    – SFMC_User
    Commented Jun 2, 2015 at 21:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .