Regex expressions are used in NinjaCat when you want to add multiple conditions to be met for the same filter. For example, you would like Campaign Name to contain multiple campaigns, not just filter on one. Or you would like to do a keyword report but exclude all keywords that contain the brand of the agency. Here is a few common use-cases for a Regex expression, along with the expression that you would use with each scenario.
A great resource for assisting to build your Regex expressions is www.regex101.com.
How to INCLUDE a list of items:
Suppose that you had two campaign names that you wanted to include in your list of items. Here is how that might look for campaigns A and campaigns B:
^.*(Campaign A|Campaign B).*$
https://regex101.com/r/proIOt/1
Here's how this works:
- ^ Must match start of the line
- .* Match any characters after the start of the line
- (A|B) - Must match either A or B
- .* Match any characters before the end of the line
- $ Must match end of the line
How to EXCLUDE a list of items:
Suppose that you had a scenario where you wanted to exclude two items from your data set: WEBSITE1.com, and WEBSITE2.com. Here is the regex expression that you would use in this case:
^((?!WEBSITE1\.com|WEBSITE2\.com).)*$
https://regex101.com/r/sP9OBI/2
Here's how this works:
- ^ Must match start of the line
- ?| Negative look ahead - must not match WEBSITE1.com or WEBSITE2.com
- \. Match the character .
- . Matches any character
- ()* Greedy operator - repeat the previous step as much as possible
- $ Must match end of the line
How to both INCLUDE and EXCLUDE data:
Suppose you had a scenario where you wanted to include the word "annual" in your search results, but exclude the expression "retargetting". Here is the regex expression that you will need to use that did this:
^((?!retargetting).)*(annual)((?!retargetting).)*$
https://regex101.com/r/E4z4Kw/2
Essentially this is how it's working:
- must match start of line
- after start of line, not allowed to match "retargetting"
- then must match "annual"
- after that, not allowed to match "retargetting"
- then must match end of line
Comments
0 comments
Article is closed for comments.