Count number of occurrences of a word in a text

I have an email tracking app where I receive HTML of email body from different brands through a webhook which I store in a text field.

Example of HTML:

     <meta content="text/html;" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta content="IE=edge" />  
   <div style="margin: 0; padding: 0; min-width: 100%; background-color: rgb(255, 255, 255)" class="zm_4594858740468993912_parse_8574010556467682686">
<div style="display: none; font-size: 1px; line-height: 1px; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden"> Plus, Womens, Accessories, Shoes, Mens 25% OFF.</div>
<table width="100%" class="x_1076321522body" cellpadding="0" cellspacing="0" border="0"> <tr> <td style="background-color: rgb(255, 255, 255)"> <table width="100%" class="x_1076321522Wrapper" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center" style="background-color: transparent; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-top-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-left-width: 0px; border-color: rgb(34, 34, 34)">  <table width="100%" class="x_1076321522Container" cellpadding="0" cellspacing="0" border="0" style="max-width: 600px"> <tr> <td align="center" style="background-color: rgb(236, 236, 236)"> <table width="100%" class="x_1076321522Column-1" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr class="x_1076321522text"> <td style="padding: 5px 5px 5px 5px; border-width: 0px; border-style: none; font-family: &quot;Lato&quot;, sans-serif; font-size: 12px; font-weight: normal; color: rgb(34, 34, 34); line-height: 1.5; text-align: center"> <p style="margin: 0px; padding: 0px"><span style="color: rgb(72, 160, 220)"><span style="font-size: 12px"><span style="font-family: lato, arial, helvetica, sans-serif">FREE SHIPPING OVER $75&nbsp;&amp; FREE RETURNS IN&nbsp;STORES</span></span></span></p>
</td> </tr> </table> </td> </tr> </table> </td> </tr> </table>  </td> </tr> </table> <table width="100%" class="x_1076321522Wrapper" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center" style="background-color: transparent; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-top-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-left-width: 0px; border-color: rgb(34, 34, 34)">  <table width="100%" class="x_1076321522Container" cellpadding="0" cellspacing="0" border="0" style="max-width: 600px"> <tr> <td align="center" style="background-color: transparent"> <table width="100%" class="x_1076321522Column-1" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr class="x_1076321522image"><td align="center" style="padding: 10px 10px 10px 10px"> <a href="http://enews.rainbowshops.com/q/z6GVttYvIag0X16HwTmmP4LNo4OxgeLize7ZcOJc2hpdmFtQHNoaXZhbWtyLm9yZ8OIPbUFfdR_cq0LpbqsktjF8nzSyDA" title="Rainbow" target="_blank"><img src="https://mediacdn.espssl.com/7856/Shared/template/Rainbow-white-bg.png" alt="Rainbow" style="display: block; width: 100%; max-width: 250px !important; border: 0px" width="250" /></a> </td></tr><tr class="x_1076321522nav"> <td align="center" style="font-size: 0; padding: 0px 0px 0px 0px; line-height: 1.5; letter-spacing: 0px"> <span style="color: rgb(34, 34, 34)"><a href="http://enews.rainbowshops.com/q/WDlD3iLhkpS0XWvOk6uBHv3Dw_Xgb2AwjVzZcOJc2hpdmFtQHNoaXZhbWtyLm9yZ8OIYN7YXzE5cZOLUHNUU0Eu6Q2nZ0Q" target="_blank" style="font-family: &quot;Roboto&quot;, sans-serif; font-size: 12px; font-style: normal; color: rgb(34, 34, 34); display: inline-block; background-color: transparent; border-width: 1px; border-style: solid; border-color: rgb(255, 255, 255); text-decoration: none; padding: 10px; box-sizing: border-box"><strong style="font-weight: normal">WOMENS</strong></a></span> <span style="color: rgb(34, 34, 34)"><a href="http://enews.rainbowshops.com/q/EQDEfEV0Jl90X2hrOKChNBSt3WCMQc4sukcZcOJc2hpdmFtQHNoaXZhbWtyLm9yZ8OIHU_ZBksicraLO5ezY5s4awBRI0A" target="_blank" style="font-family: &quot;Roboto&quot;, sans-serif; font-size: 12px; font-style: normal; color: rgb(34, 34, 34); display: inline-block; background-color: transparent; border-width: 1px; border-style: solid; border-color: rgb(255, 255, 255); text-decoration: none; padding: 10px; box-sizing: border-box"><strong style="font-weight: normal">PLUS SIZE</strong></a></span> <span style="color: rgb(34, 34, 34)"><a href="http://enews.rainbowshops.com/q/nzXa3h4eXNc0XrOFfbR_jhGkSdAL86uJl5aZcOJc2hpdmFtQHNoaXZhbWtyLm9yZ8OI7097CD0me5ALpXb24dYOxKuZIcg" target="_blank" style="font-family: &quot;Roboto&quot;, sans-serif; font-size: 12px; font-style: normal; color: rgb(34, 34, 34); display: inline-block; background-color: transparent; border-width: 1px; border-style: solid; border-color: rgb(255, 255, 255); text-decoration: none; padding: 10px; box-sizing: border-box"><strong style="font-weight: normal">MENS</strong></a></span> <span style="color: rgb(34, 34, 34)"><a href="http://enews.rainbowshops.com/q/reY5KJi_pQQ0Xk12OABzH-TDaqU1IVTfFdhZcOJc2hpdmFtQHNoaXZhbWtyLm9yZ8OIH_e4f2G1cbqLK6UZUsStLuRbwsQ" target="_blank" style="font-family: &quot;Roboto&quot;, sans-serif; font-size: 12px; font-style: normal; color: rgb(34, 34, 34); display: inline-block; background-color: transparent; border-width: 1px; border-style: solid; border-color: rgb(255, 255, 255); text-decoration: none; padding: 10px; box-sizing: border-box"><strong style="font-weight: normal">KIDS</strong></a></span> <span style="color: rgb(34, 34, 34)"><a href="http://enews.rainbowshops.com/q/A1eG9mC0GhK0Xq5sMpuKWwjMRssw4LIdqoiZcOJc2hpdmFtQHNoaXZhbWtyLm9yZ8OIQyQyH3PVf4bLkEEDhZSHSp0ojOw" target="_blank" style="font-family: &quot;Roboto&quot;, sans-serif; font-size: 12px; font-style: normal; color: rgb(34, 34, 34); display: inline-block; background-color: transparent; border-width: 1px; border-style: solid; border-color: rgb(255, 255, 255); text-decoration: none; padding: 10px; box-sizing: border-box"><strong style="font-weight: normal">SHOES</strong></a></span> <span style="color: rgb(34, 34, 34)"><a href="http://enews.rainbowshops.com/q/OOPMm3cp4Oa0X9NBgnwWxmukDwNCWpVUW3kZcOJc2hpdmFtQHNoaXZhbWtyLm9yZ8OICPJVhRIce5vLofzizP1dwqQH1XA" target="_blank" style="font-family: &quot;Roboto&quot;, sans-serif; font-size: 12px; font-style: normal; color: rgb(34, 34, 34); display: inline-block; background-color: transparent; border-width: 1px; border-style: solid; border-color: rgb(255, 255, 255); text-decoration: none; padding: 10px; box-sizing: border-box"><strong style="font-weight: normal">SALE</strong></a></span> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table>  </td> </tr> </table> <table width="100%" class="x_1076321522Wrapper" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center" style="background-color: transparent; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-top-width: 0px; border-bottom-width: 0px; border-right-width: 0px; border-left-width: 0px; border-color: rgb(34, 34, 34)">  <table width="100%" class="x_1076321522Container" cellpadding="0" cellspacing="0" border="0" style="max-width: 600px"> <tr> <td align="center" style="background-color: transparent"> <table width="100%" class="x_1076321522Column-1" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr class="x_1076321522image"><td align="center" style="padding: 0px 0px 0px 0px"> <a href="http://enews.rainbowshops.com/q/ZRwi9OFuqkI0XAKWXXo2Ki_cajmwthYaR38ZcOJc2hpdmFtQHNoaXZhbWtyLm9yZ8OIfqJrXkuEfZkLDUU0Jbi0H3nelYg" title="MEMORIAL DAY SALE UP TO 80% OFF HURRY ENDS SOON!" target="_blank"><img src="https://mediacdn.espssl.com/7856/Shared/_Creative/2024/05/0526/052624-1-MDS-Menu_01.gif" alt="MEMORIAL DAY SALE UP TO 80% OFF HURRY ENDS SOON!" style="display: block; width: 100%; max-width: 600px !important; border: 0px" width="600" /></a> </td></tr> </table> </td> </tr> </table> <table width="100%" class="x_1076321522Column-1" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="center"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr class="x_1076321522text"> <td style="padding: 30px 30px 30px 30px; border-width: 0px; border-style: none; font-family: &quot;Lato&quot;, sans-serif; font-size: 16px; font-weight: normal; color: rgb(34, 34, 34); line-height: 1.5; text-align: center"> <p style="margin: 0px; padding: 0px"><span style="font-size: 15px"><span style="color: rgb(0, 0, 0)">Don't let these incredible discounts slip away!<br />
Shop now and&nbsp;score unbeatable deals.</span></span></p>

Now I want to count how many images, links, etc are present in this email.

One way I can think of is basically counting how many times a keyword like “<img src” is present which will give me the image count. Similarly, count for <a href would give me a link count.

Can you please help me figure out how can I count the occurrence of words like “<img src” in a text field?

Also, do you know any other better way to get the count of images, emoji, video, etc from a HTML email?

Sure. You could use a RegEx pattern.

image

Arbitrary Text is your text, whether that’s from a group, or an input value etc.

The RegEx pattern is <img[^>]*\s+src=“([^”]+)"

Count then returns how many matches.

Just adjust the RegEx for each tag, i.e a tag, h1 and so on.

image

Quick solution - not sure if it’s the best one but hopefully useful for you? :slight_smile:

This topic was automatically closed after 70 days. New replies are no longer allowed.