Parentheses ( ), brackets [ ], and curly brackets { } are very useful characters for grouping words and ranges of letters and numbers, and being very precise in exactly which URLs you are targeting. Here are a few examples of the characters and their uses:
(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.
Parentheses
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. This is what we used earlier:
To use this example, you would add the following to your regex fields: Subdomain : TLD : Path : |
This examples targets blog.mycats.com/peggysue.html
AND blog.mycats.com/turbo.html
Brackets and Curly Brackets
You can use the brackets to target a range of letters (like a-z or a-f) or numbers (0-9, 1-5). You can also use the curly brackets to ask for a specific number of letters or numbers, or a range that you will allow.
If you want to target a survey across several sections of your website, you can use the OR pipe, or the brackets, if they have a similar format. For example, if you want 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
You can use the brackets to show the letter range [a-z]
and curly brackets to determine how many letters you will allow {2}
.
To use this example, you would add the following to your regex fields: Subdomain : TLD : Path : |
You can put them together to target pages that have a specific format in the URL, like 6 letters and 8 numbers.
To use this example, you would add the following to your regex fields: Subdomain : TLD : Path : |
This regex WILL MATCH pages like:
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
It will NOT MATCH 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
If you'd like more flexibility in the ranges of letters and numbers in the pages you want to target, the curly brackets can be used for this as well.
Say you want to target the same kinds of pages as before, but there can be 4-8 letters, and 2-8 numbers.
To use this example, you would add the following to your regex fields: Subdomain : TLD : Path : |
This will 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
Multi-Digit Number Ranges
One of the very few restrictions in regular expressions is that it doesn't know how to deal with numbers greater than 9. To do ranges in the double or triple digits, you must specify the range of each digit.
For example, if you want to target pages with numbers 25-50, you would have to use a few sets of numbers and ranges. Specifically, you must define 25-29, then 30-49, then 50. First we will make each range, and then put them together into a single regex.
2[5-9]
will match 25-29
(3|4)[0-9]
will match 30-30 and 40-49
50
will match 50
Since we want to target any of these pages, we use the OR pipe to separate each number range.
(2[5-9]|(3|4)[0-9]|50)
To use this example, you would add the following to your regex fields: Subdomain : TLD : Path : |
Comments
0 comments
Article is closed for comments.