Google Analytics supports regular expressions like (. * + ()[]) so that users can create more powerful implementations in their Filters options to track exact keywords typed by online users.
Regular expressions are special characters that match or capture portions of a field, as well as the rules that govern all characters. Most of the filters included in Google Analytics use these expressions to match the data and perform an action, when a match is achieved.
Now, if you check on the below images, you find “Field A & B” with those regular expressions; so whats the use & how to use those expression is mentioned below:
Click on each character’s description to read a detailed article describing how to use it.
Wildcards
. Matches any single character (letter, number or symbol) goo.glematches gooogle, goodgle,goo8gle * Matches zero or more of the previous item The default previous item is the previous character. goo*glematches gooogle,goooogle + Just like a star, except that a plus sign must match at least one previous item gooo+gle matches goooogle, but nevergoogle. ? Matches zero or one of the previous item labou?r matches both labor and labour | Lets you do an “or” match a|b matches a or b
Anchors
^ Requires that your data be at the beginning of its field ^site matches site but not mysite $ Requires that your data be at the end of its field site$ matches site but not sitescan
Note: to understand why anchors are necessary, please read Tips for Regular Expressions at the bottom of this page.
Grouping
() Use parenthesis to create an item, instead of accepting the default Thank(s|you) will match bothThanks and Thankyou [] Use brackets to create a list of items to match to [abc] creates a list with a, band cin it – Use dashes with brackets to extend your list [A-Z] creates a list for the uppercase English alphabet
Other
\ Turns a regular expression character into an everyday character mysite\.com keeps the dot from being a wildcard
Tips for Regular Expressions
- Make the regular expression as simple as possible.
- Be sure to use a backslash, if you have characters like “?” or “.” and you wish to match those literal characters — otherwise, they will be interpreted as special regular expression characters.
- Not all regular expressions include special characters. For example, you can specify that a Google Analytics goal be a regular expression, and even if you don’t have any special characters, your goal will be interpreted according to the rules of regular expressions.
- Regular expressions are greedy. For example, site matches mysite and yoursiteandsitescan. If site is your regular expression, it is the equivalent of asking to match to all strings that contain site. Therefore, you should use anchors whenever necessary, to get a more accurate match. ^site$, which uses both a beginning ^ and ending $ anchor, will ensure that the expression has to start with site and end with site and include nothing else. Notice, too, that there were no special characters in the regular expression site – it is interpreted as a regular expression only if it is in a regular expression-sensitive field.
Note: The content is/may be copied from other link sources to make it simple, easy & informative to understand. For ’&” regular expression, I didn’t get any details.
Add Comment