google.cloud.forseti.common.util.regular_exp module

Regex utility module.

escape_and_globify(pattern_string, wildcard_is_zero_or_more=False)[source]

Given a pattern string with a glob, create actual regex pattern.

To require > 0 length glob, change the “*” to “.+”. This is to handle strings like “*@company.com”. (The actual regex would probably be “.*@company.com”, except that we don’t want to match zero-length usernames before the “@”.)

Special case the pattern ‘*’ to match 0 or more characters.

Parameters:
  • pattern_string (str) – The pattern string of which to make a regex.
  • wildcard_is_zero_or_more (bool) – Whether the wildcard designates 0 or more versus 1 or more for wildcards after the prefix.
Returns:

The pattern string, escaped except for the “*”, which is

transformed into “.+” (match on one or more characters).

Return type:

str