Question mark (?), plus sign (+), asterisk (*) [Legacy]

You are viewing a legacy article about Universal Analytics. Learn more about Google Analytics 4 replacing Universal Analytics.

Question mark (?)

The question mark (?) matches the preceding character 0 or 1 times.

For example, 10? matches:

  • 1
  • 10
Example

Match an IP address with 1 or 2 digits in the last section.

For example, 216\.239\.32\.\d\d? matches:

  • 216.239.32.2
  • 216.239.32.34

This example uses the backslash to escape the decimal, and uses \d to match any digit.

Plus sign (+)

The plus sign (+) matches the preceding character 1 or more times.

For example, 10+ matches:

  • 10
  • 100
  • 1000
  • etc.
Example

Match an IP address with 1 or more digits in the last section.

For example, 216\.239\.32\.\d+ matches:

  • 216.239.32.2
  • 216.239.32.34
  • 216.239.32.567

This example uses the backslash to escape the decimal, and uses \d to match any digit.

Asterisk (*)

The asterisk or star matches the preceding character 0 or more times.

For example, 10* matches:

  • 1
  • 10
  • 100
  • 1000
  • etc.
Example

Match an IP address with 1 or more digits in the last section.

For example, 216\.239\.32\.\d* matches

  • 216.239.32.2
  • 216.239.32.34
  • 216.239.32.567

This example uses the backslash to escape the decimal, and uses \d to match any digit.

If you need to match more than just the preceding item, you can combine the asterisk with the dot (.*). The dot matches any preceding item, and then the asterisk will match that item zero or more times, which lets you match things like all URIs that begin and end with the same characters, regardless of how many characters are in between. For example, /mens/.*html matches:

  • /mens/shirts/oxford.html
  • /mens/shirts/oxford/shortsleeve.html

Was this helpful?

How can we improve it?
Search
Clear search
Close search
Google apps
Main menu
12855852458844218013
true
Search Help Center
true
true
true
true
true
69256
true
false