Regular expression examples

Written by Julie Trenque

Updated on 06/24/2021

3 min

Advanced

Was this content useful?

Kameleoon offer to target any type of URL thanks to regular expressions.

Here is a detailed list of the most used regular expressions:

  • . = Replace one character by any other one in your regular expression. For example, the expression Kamele.on will target URLs containing KameleoonKamele0nKamele8on, etc.
  • * = Delete the previous character or add the same character once or several times after. For example, the expression Kameleoo*n, will target URLs containing KameleonKameleoonKameleooon, etc.
  • ? = Delete or leave the previous character. For example, Kameleoo?n will target URLs containing Kameleon and Kameleoon.
  • + = Add the previous character once or several times. For example, Kameleo+n will target URLs containing Kameleoon and Kameleoooon.
  • | = Target several chains of character. It is an exclusive “Or”. For example, Kameleoon|Chameleoon will target Kameleoon or Chameleoon.
  • ^ = Shows the begining of the chain. ^Kameleoon will target URLs starting with Kameleoon.
  • $ = Shows the end of the chain. Kameleoon$ will target URLs ending with Kameleoon.
  • () =Creates groups of several elements. Usually, this regular expression is combined with the |. For example, Kameleoon (AB Testing|Conversion) Tool will target Kameleoon AB Testing Tool or Kameleoon Conversion Tool.
  • [] = Will be replaced by each character inside the []. For example,/Kameleoon/[234] will target Kameleoon 2Kameleoon 3 and Kameleoon 4.
  • - = /kameleoon/[2-9] will target every page from Kameleoon 2 to Kameleoon 9.
  • {} = Gives precise limits of the occurences. For example, Kameleo{2,4}n will target URLs containing KameleoonKameleooon, or Kameleoooon.

Note : If your character chain contains one of the special characters (,.*, etc.), simply put the antislash \ before it.

Note : These expressions are case sensitive.

Here are some examples of the use of regular expressions:

  • ^.{10}$ = targets URLs containing precisely 10 characters.
  • general\.(html|php)$ = targets URLs ending with either general.php or general.html. However, URLs ending with general.htm will be excluded.
  • \/fr\/ = targets URLs containing /fr/.
  • \/annexes\/.*\d{3} = targets URLs containing the fragment /annexes/ and a 3 digit number.
  • \/annexes\/.*\d{2}.*test\.html$ = targets URLs containing the fragment /annexes/, and a 2 digit number ending with test.html.