[UA] Dot (.) and backslash (\)

Some characters have one meaning in regular expressions and completely different meanings in other contexts. For example, in regular expressions, the dot (.) is a special character used to match any one character. In written language, the period (.) is used to indicate the end of a sentence. In mathematics, the decimal point (.) is used to separate the whole part of a number from the fractional part.

Regular expressions first evaluates a special character in the context of regular expressions: if it sees a dot, then it knows to match any one character.

For example, the regular expression 1. matches:

  • 11
  • 1A

The regular expression 1.1 matches

  • 111
  • 1A1

If you were to provide an IP address as a regular expression, you would get unpredictable results. For example, the regular expression 0.0.0.0 matches:

  • 0102030
  • 0a0b0c0

In order to tell regular expressions to see the dot in its original context as a separator for the different parts of the IP address and not as a special character used to match any other character, you need to provide a signal to that effect. The backslash (\) is that signal. When regular expressions sees a backslash, it knows that it should interpret the next character literally. A regular expression to match the IP address 0.0.0.0 would be:

0\.0\.0\.0

Use the backslash to escape any special character and interpret it literally; for example:

  • \\ (escapes the backslash)
  • \[ (escapes the bracket)
  • \{ (escapes the curly brace)
  • \. (escapes the dot)

Was this helpful?

How can we improve it?
true
Choose your own learning path

Check out google.com/analytics/learn, a new resource to help you get the most out of Google Analytics 4. The new website includes videos, articles, and guided flows, and provides links to the Google Analytics Discord, Blog, YouTube channel, and GitHub repository.

Start learning today!

Search
Clear search
Close search
Google apps
Main menu
8040962754550266765
true
Search Help Center
true
true
true
true
true
69256
false
false