What are regular expressions, and how and where to use them in your Optable DCN
Short for regular expression, a regex is a string of text that allows you to create patterns that help match, locate, and manage text.
Regular expression (regex) syntax differs slightly between programming languages and platforms. Optable uses the RE2 Syntax. You can use an online tool like this one to test your regex.
Optable allows you to use regex in a few places within your DCN's UI, namely when setting up the allowed HTTP origins of a source, or when you define query audiences.
Example of a regex matching with case insensitive variations of Romance, Romantic Comedy, and Comedy as favourite TV show genre
Example of a regex matching all the HTTP origins of "mywebsite", where the protocol (http / https), the subdomain (www. / subdomain. / <blank> ) and the extension (.com / .co / .org / .net / .php) vary.
Regex can save you a lot of time and help you perform actions that would be impossible to perform otherwise. Suppose a trait for which you have thousands of possible values, and you want to query it for the word
shoe. You will want variations such as
Running shoes, but not
shoelace. Listing all possible variations and exceptions would be nearly impossible.
With regex, you can do this:
(^| )(S|s)hoes?([ .,;:!?]|$)
Breaking the expression down into its components:
()are grouping instructions/modifiers together
(^| )means the expression must either start with the next instruction, or with a space, thus preventing words like
goody two-shoesfrom being considered a valid query result, because of the
-before the word
(S|s)allows the the lower and uppercase version of
s. Another way of achieving this is by using modifiers such as
(?i)at the beginning of the query.
?means the previous character, or group of character if between
(), is optional. In the expression
(S|s)hoes?, the following values are considered valid:
representing a list or a class of characters. For instance,
[0-9]means any numeric value,
[A-Z]means uppercase letters.
- The current expression
([ .,;:!?]|$)means that the variations must end with
(S|s)hoes?, or can be followed by an empty space or specific special characters (but not others not listed, such as