What is Regex?
Regular Expressions are a code based on punctuation signs to describe a chain of characters according to specific conditions.
For instance, the "." looks for any character. If you write "website.", the dot will bring you "websites", "websitez", "website4", etc.
Using Regex
Regex can be used in Contentsquare to define group pages for mappings or for segment conditions.
Regex use punctuation signs:
- “.” means you’re looking for one character
- “..” means you’re looking for two characters
- “*” means you’re looking for the precedent token once, several times or 0 time
- “+” means you’re looking for at least one character, or more
- “?” means you’re looking for one OR two undefined characters, not more
- "/" neutralizes the regex meaning of any punctation above. If you're looking for real punctuation in the URLs, then you must backlash it. For instance, If you’re looking for a “?”, type “\?” in your regex.
Regex examples
Typeaword.
"Typeaword" + one character only, any character
Typeawordd
Typeawordd8
Typeaword..
"Typeaword" + two characters, any character
Typeawordd8
Typeaword?
Typeaword.*
"Typeaword" + any character (.) 0, 1 or several times (*)
Typeaword1
Typeaword1111
You can combine rules
For instance: w*\.go+gle\.com www.ggle.com will find:
- www.gogle.com
- www.google.com
- wwwwww.gooooooooooogle.com
How to create a new page based on Regex?
Scenario: Defining product pages in my mapping
If all my product pages are structured this way:
_P + sequence of numbers
https://www.mysite.com/fragrance-beauty/makeup_P0171900C49332
Then, the regex to use will be :
/([0-9a-zA-Z\-]*)_P([0-9]+)(.*)
What are Regex creation limitations?
Conditions & characters |
Supported number |
Regex conditions per page group | Up to 32 |
Characters in text fields | Up to 255 |
Special characters on Regex conditions field |
|
A condition is composed of: a condition type (path, host, query) + an operator (matches regex or does not match regex) + a regex value