+4 votes
by (6.7k points)
Hey guys, I'm trying to write a regex "or" statement to track Bing conversions from urls containing either: /checkout_finalize_mc OR /checkout_with_pay_token Can anyone weigh in on the best way to get this done? I'm light on regex and concerned the underscores could also have an unintended effect. Any help appreciated!  
Hey guys, I'm trying to write a regex "or" statement to track Bing conversions from urls c

3 Answers

+3 votes
by (3.1k points)
 
Best answer
If exact strings, example foo and bar, with OR the syntax goes like ^(foo|bar)$
by (6.7k points)
Hi Joel, thanks for jumping in. Those are exact strings but hoping I can land on a "contains" "or" statement but also trying to avoid the underscores getting in the way. So something like: url contains "finalize_mc" or "with_pay_token"
by (3.1k points)
Just add wildcards before and after ^. *(foo|bar). *$
by (3.1k points)
@luedtke42 just replace foo and bar with your two strings
by (6.7k points)
So you think the below example would work? Or do I need astericks before "finalize" and before "with" ^. *(finalize_mc|with_pay_token). *$
by (3.1k points)
@luedtke42 those are wrong and dangerous
by (3.1k points)
@luedtke42 put the exact strings you want the complete thing for safety
by (3.1k points)
If you want "contains" "or" you have to put the wildcards either in before or after or both. It depends on your strings if they will appear at the end or start or middle of the URL.  
by (6.7k points)
Ok so to finish it up: the urls would be: xyz. com/checkout_finalize_mc OR xyz. com/checkout_with_pay_token so an asterick before *(finalize_mc|with_pay_token) should work then?  
by (3.1k points)
@luedtke42 wrong. It would match pages with those words. Not sure you want that. Put the exact strings as sensible as possible.  
by (6.7k points)
As long as order is considered that's what I'm going for. The concern w/ exact strings is we're not sure if a trailing backslash will be present in all cases.  
by (3.1k points)
"xyz. com/checkout_(finalize_mc|with_pay_token)$" Are you sure you need contains? Where are the variables? At the end? If so then "xyz. com/checkout_(finalize_mc|with_pay_token). *$"
by (3.1k points)
@luedtke42 if trailing backslash isn't always inserted sounds like a URL structure problem. Magento has this issue. Fixable by htaccess directives so the trailing backslash is always added. Better for SEO too so you avoid duplicate URLs that have with and without trailing backslash
by (3.1k points)
@luedtke42 this is not "contains" this is trailing backslash with or without. "xyz. com/checkout_(finalize_mc|with_pay_token)/? $"
by (6.7k points)
Thanks Joel
by (3.1k points)
@luedtke42 no problem. Test it out first. Depending on platform there are nuances with REGEX syntax
+1 vote
by (3.1k points)
Are those exact strings or did you mean with a token variable?  
0 votes
by (3.1k points)
^checkout_. +$ Why not anchor it to checkout_?  
by (6.7k points)
Main reason is that there are other checkout steps (i. e. review_order, etc) that don't indicate a true purchase.  
The Google AdWords Group is where you can always find questions, answers, advice, reviews & recommendations from other community members about successful search engine marketing (SEM) ads through Google AdWords.

Related questions

...