top of page

How to use RegEx

  • 5 days ago
  • 3 min read

There are many uses for RegEx, but in the Extellio platform, it can be used to create segments. Here are some examples of how you can use RegEx for your segments.


  • Visit entry URL = .*(support|sales).* - meaning the URL contains one of the two words, in this example "support" or "sales"

  • Pageview URL = ^https.* - meaning the URLs must start with "https"

  • Event URL = .*contact\/$ - meaning the URLs must end with "contact/"


All of these examples can be created the traditional way too (using the filters in the segment editor), but they are easier to combine when using RegEx.


Syntax

kinds of single-character expressions

examples

any character, possibly including newline (s=true)

.

character class

[xyz]

negated character class

[^xyz]

Perl character class

\d

negated Perl character class

\D

ASCII character class

[[:alpha:]]

negated ASCII character class

[[:^alpha:]]

Unicode character class (one-letter name)

\pN

Unicode character class

\p{Greek}

negated Unicode character class (one-letter name)

\PN

negated Unicode character class

\P{Greek}

Composites


xy

x followed by y

x|y

x or y (prefer x)

Repetitions


x*

zero or more x, prefer more

x+

one or more x, prefer more

x?

zero or one x, prefer one

x{n,m}

n or n+1 or ... or m x, prefer more

x{n,}

n or more x, prefer more

x{n}

exactly n x

x*?

zero or more x, prefer fewer

x+?

one or more x, prefer fewer

x??

zero or one x, prefer zero

x{n,m}?

n or n+1 or ... or m x, prefer fewer

x{n,}?

n or more x, prefer fewer

x{n}?

exactly n x

Implementation restriction: The counting forms x{n,m}, x{n,}, and x{n} reject forms that create a minimum or maximum repetition count above 1000. Unlimited repetitions are not subject to this restriction.


Empty strings


^

at beginning of text or line (m=true)

$

at end of text (like \z not \Z) or line (m=true)

A

at beginning of text

\b

at ASCII word boundary (\w on one side and \W, \A, or \z on the other)

\B

not at ASCII word boundary

\g

at beginning of subtext being searched (NOT SUPPORTED) PCRE

\G

at end of last match (NOT SUPPORTED) PERL

\Z

at end of text, or before newline at end of text (NOT SUPPORTED)

\z

at end of text

Escape sequences


\a

bell (≡ \007)

\f

form feed (≡ \014)

\t

horizontal tab (≡ \011)

\n

newline (≡ \012)

\r

carriage return (≡ \015)

\v

vertical tab character (≡ \013)

\*

literal *, for any punctuation character *

\123

octal character code (up to three digits)

\x7F

hex character code (exactly two digits)

\x{10FFFF}

hex character code

\C

match a single byte even in UTF-8 mode

\Q...\E

literal text ... even if ... has punctuation

Character class elements


x

single character

A-Z

character range (inclusive)

\d

Perl character class

[:foo:]

ASCII character class foo

\p{Foo}

Unicode character class Foo

\pF

Unicode character class F (one-letter name)

Named character classes as character class elements


[\d]

digits (≡ \d)

[^\d]

not digits (≡ \D)

[\D]

not digits (≡ \D)

[^\D]

not not digits (≡ \d)

[[:name:]]

named ASCII class inside character class (≡ [:name:])

[^[:name:]]

named ASCII class inside negated character class (≡ [:^name:])

[\p{Name}]

named Unicode property inside character class (≡ \p{Name})

[^\p{Name}]

named Unicode property inside negated character class (≡ \P{Name})

Perl character classes (all ASCII-only)


\d

digits (≡ [0-9])

\D

not digits (≡ [^0-9])

\s

whitespace (≡ [\t\n\f\r ])

\S

not whitespace (≡ [^\t\n\f\r ])

\w

word characters (≡ [0-9A-Za-z_])

\W

not word characters (≡ [^0-9A-Za-z_])

For a more complete list, go here.

 
 

Related Posts

See All
Turn user actions into insights with events

Let's start with what an event is In simple terms, an event is just something a user does that can be measured. It could be clicking a button, opening a menu or using a product filter - any action yo

 
 
Add E-commerce

To measure Ecommerce performance in Extellio, you need to add tracking to the key moments of your customer’s purchase journey. By placing Extellio’s JavaScript tracking snippets on your product pages,

 
 
Introduction to the new analytics

Note: Analytics is currently in Beta and will be updated regularly as new improvements are released. If you notice differences between the figures in the new Analytics and your previous data, it’s b

 
 
bottom of page