In Swift Performance you can apply Regex in different places, mostly to exclude URLs of parts from caching.

What is REGEX (Regular Expressions)?

A regular expression is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids. You are probably familiar with wildcard notations such as *.txt to find all text files in a file manager. The regex equivalent is .*\.txt.

But you can do much more with regular expressions. In a text editor like EditPad Pro or a specialized text processing tool like PowerGREP, you could use the regular expression \b[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,6}\b to search for an email address. Anyemail address, to be exact. A very similar regular expression can be used by a programmer to check if the user entered a properly formatted email address. In just one line of code, whether that code is written in Perl, PHP, Java, a .NET language or a multitude of other languages.

Since “regular expressions” is a mouthful, you will usually find the term abbreviated as “regex” or “regexp”. We prefer “regex”, since it can be easily pluralized as “regexes”.

Since PHP 7.3 you need to escape hyphen as well: #/product\-item(.*)/#

Here you can test if your Regex is valid.

Example 1
exclude all multilingual contact pages, such as /contact – /contact-us – /contactos – /kontakt


Example 2
For images


Example 3
Exclude all pages/URLs which contain


Example 4
target all “/store/something” urls but NOT “/store/” itself


Example 5
All pages, except homepage


Example 6
for date archives


Example 7
for tags