Home > Net >  RegEx at Google Tag Manager
RegEx at Google Tag Manager

Time:11-24

I'm using Google Tag Manager to configure events for an e-commerce and I need search for the word "trash" in the string below:

"SVGSVGElement: html > body.template-home.overflow-none > div.theme-w" "ide#container > form.js-ajax-cart-panel.js-fullscreen-modal.ajax-car" "t-container.modal-right.modal-xs.modal-xs-right.modal-xs-right-out#a" "jax-cart-details > div.modal-xs-dialog > div.modal-content > div.aja" "x-cart-body.modal-right-body.modal-xs-body > div.js-ajax-cart-list.a" "jax-cart-table.pull-left > div.js-cart-item.js-cart-item-shippable.a" "jax-cart-item > div.ajax-cart-item-delete-col.cart-delete-container." "ajax-cart-item-col.text-right > button.cart-btn-delete.ajax-cart-btn" "-delete.pull-right.p-top-none > div.cart-delete-svg-icon.svg-icon-te" "xt > svg.svg-trash-icon"

Question:

What expression do I use to search for the word "trash" in the string at Google Tag Manager?

Thanks for listening!

I have already tested the following RegEx:

\btrash\b /(trash\d (\.\d)*)/I /trash/g

But none of them worked.

CodePudding user response:

Welcome to Stack overflow!

try this: \b\S*trash\S*\b (with a global modifier)

demo: https://regex101.com/r/AtfgvE/1

It will find any word (separated by spaces) that has the word trash in it (so for example svg.svg-trash-icon will be matched)

CodePudding user response:

Because your trigger is {{Click Element}}

It's not a string or text that you see on the preview.

If you want to target this element svg.svg-trash-icon

I would suggest you use:

Click Element Match CSS Selector svg.svg-trash-icon

OR

Click Element Match CSS Selector svg[class*='trash']

// This would match all svg element that class contains trash

  • Related