Skip to main content

BuckRegex

Type created by the regex function.

BuckRegex.all_match

def BuckRegex.all_match(
strings: list[str],
/,
) -> bool

Determine if the regex matches a substring of every one of the given strings. Returns True for an empty list. Returns as soon as a non-matching element is found, without validating the remaining elements.

Behaves like calling match on each element, but is significantly faster on large lists because it crosses from Starlark into native code only once.


BuckRegex.any_match

def BuckRegex.any_match(
strings: list[str],
/,
) -> bool

Determine if the regex matches a substring of any of the given strings. Returns False for an empty list. Returns as soon as a match is found, without validating the remaining elements.

Behaves like calling match on each element, but is significantly faster on large lists because it crosses from Starlark into native code only once.


BuckRegex.match

def BuckRegex.match(
str: str,
/,
) -> bool

Determine if the regex matches any substring of the given string.


BuckRegex.replace_all

def BuckRegex.replace_all(
haystack: str,
replacement: str,
/,
) -> str

Replace all matches of the regex in the given string with the replacement string. Takes the following parameters: * haystack - The string you will be regex matching against * replacement - The replacement string to replace the regex matches with

Returns a new string with all regex matches replaced.

Sample usage:

regex_pattern = regex(r"foo")
result = regex_pattern.replace_all("foo bar foo", "baz")

result equals "baz bar baz" in this example