Here is how you can use Parentheses ( ), brackets [ ], and curly brackets { } in regular expression:
-
(a|b) - Matches a OR b
-
[xyz] – Matches any single character in the brackets: x, y, OR z.
-
[^a-z] – When inside of a character class, the ^ means NOT. Here, match anything that is NOT a lowercase letter.
-
[A-Z] – Capital A through Capital Z.
-
[a-z]{2} – Exactly 2 a-z letters.
How to Use Parenthesis
Using the parentheses and the OR pipe, you can tell your regex to target one word (sometimes called a "string") or another in your URL.
Add the following characters in the regex fields:
Subdomain : blog
TLD : mycats.com
Path : (peggysue|turbo)\.html
to target the URLs: blog.mycats.com/peggysue.html AND blog.mycats.com/turbo.html.
How to Use Brackets and Curly Brackets
By using
-
Brackets - you can target a range of letters (like a-z or a-f) or numbers (0-9, 1-5). You can also use the
-
Curly brackets - you can ask for a specific number of letters, numbers, or a range you wish to allow.
If you want to use the brackets to show the letter range [a-z] and curly brackets to determine letter count by allowing {2}, add the following characters in the regex fields:
Subdomain : www
TLD : international.com
Path : [a-z]{2}\/products
to target the following sections:
-
www.international.com/en/products
-
www.international.com/ca/products
-
www.international.com/uk/products
-
www.international.com/au/products
-
www.international.com/nz/products
In this way, target a survey across several sections of your website, you can use the OR pipe, or the brackets if they have a similar format.
Further, if you want to target pages with a specific URL format, like six letters and eight numbers, add the following characters to the regex fields:
Subdomain : (www)?
TLD : gifts-for-everyone.org
Path : holiday\/special_deals\/[a-z]{6}-[0-9]{8}
to match the following pages:
-
www.gifts-for-everyone.org/holiday/special_deals/lawnmo-45061367
-
www.gifts-for-everyone.org/holiday/special_deals/hairdr-00002239
-
www.gifts-for-everyone.org/holiday/special_deals/poster-08825041
and ignore the following pages:
-
development.gifts-for-everyone.org/holiday/special_deals/lawnmo-45061367---Wrong subdomain
-
www.gifts-for-everyone.org/holiday/special_deals/lawnmower-45061367---Wrong number of letters
-
www.gifts-for-everyone.org/holiday/special_deals/lawnmo-451367---Wrong number of numbers
NOTE: If you'd like more flexibility in the ranges of letters and numbers in the pages you want to target, the curly brackets can also be used for this.
To target the same kinds of pages mentioned above, but with 4-8 letters and 2-8 numbers, add the following characters to the regex fields:
Subdomain : (www)?
TLD : gifts-for-everyone.org
Path : holiday\/special_deals\/[a-z]{4,8}-[0-9]{2,8}
to allow the survey to be targeted at a wider range of pages, including:
-
www.gifts-for-everyone.org/holiday/special_deals/bowl-27
-
www.gifts-for-everyone.org/holiday/special_deals/heatlamp-00019223
-
www.gifts-for-everyone.org/holiday/special_deals/boots-4512
-
www.gifts-for-everyone.org/holiday/special_deals/catmitte-123380
How to Use Multi-Digit Number Ranges
Regular expressions restrict dealing with numbers greater than 9. So, to set ranges in the double or triple digits, you must specify the range of each digit.
For targeting pages with numbers 25-50, you can use a few sets of numbers and ranges. In this, you must precisely define the range from 25-29, then 30-49, and finally 50.
First, we will define each range and then put it into a single regex. Here
To target the pages : (2[5-9]|(3|4)[0-9]|50)using the OR (pipe) to separate each number range, add the following characters to your regex fields:
Subdomain : www
TLD : learning_math_is_fun.com
Path : chapter_(2[5-9]|(3|4)[0-9]|50)