Regex

class Regex(*args, **kwargs)
Constructors:

new_for_match(pattern:str, pattern_length:int, flags:int) -> Vte.Regex
new_for_match_full(pattern:str, pattern_length:int, flags:int, extra_flags:int) -> Vte.Regex, error_offset:int
new_for_search(pattern:str, pattern_length:int, flags:int) -> Vte.Regex
new_for_search_full(pattern:str, pattern_length:int, flags:int, extra_flags:int) -> Vte.Regex, error_offset:int

Constructors

class Regex
classmethod new_for_match(pattern: str, pattern_length: int, flags: int) Regex

Compiles pattern into a regex for use as a match regex with match_add_regex() or vte_terminal_event_check_regex_simple().

See man:pcre2pattern(3) for information about the supported regex language, and man:pcre2api(3) for information about the supported flags.

The regex will be compiled using <literal>PCRE2_UTF</literal> and possibly other flags, in addition to the flags supplied in flags.

Parameters:
  • pattern – a regex pattern string

  • pattern_length – the length of pattern in bytes, or -1 if the string is NUL-terminated and the length is unknown

  • flags – PCRE2 compile flags

classmethod new_for_match_full(pattern: str, pattern_length: int, flags: int, extra_flags: int) tuple[Regex, int]

Compiles pattern into a regex for use as a match regex with match_add_regex() or vte_terminal_event_check_regex_simple().

See man:pcre2pattern(3) for information about the supported regex language, and man:pcre2api(3) for information about the supported flags and extra_flags.

The regex will be compiled using <literal>PCRE2_UTF</literal> and possibly other flags, in addition to the flags supplied in flags.

If regex compilation fails, error will be set and error_offset point to error as an offset into pattern.

Added in version 0.76.

Parameters:
  • pattern – a regex pattern string

  • pattern_length – the length of pattern in bytes, or -1 if the string is NUL-terminated and the length is unknown

  • flags – PCRE2 compile flags

  • extra_flags – PCRE2 extra compile flags

Compiles pattern into a regex for use as a search regex with search_set_regex().

See man:pcre2pattern(3) for information about the supported regex language, and man:pcre2api(3) for information about the supported flags.

The regex will be compiled using <literal>PCRE2_UTF</literal> and possibly other flags, in addition to the flags supplied in flags.

Parameters:
  • pattern – a regex pattern string

  • pattern_length – the length of pattern in bytes, or -1 if the string is NUL-terminated and the length is unknown

  • flags – PCRE2 compile flags

classmethod new_for_search_full(pattern: str, pattern_length: int, flags: int, extra_flags: int) tuple[Regex, int]

Compiles pattern into a regex for use as a search regex with search_set_regex().

See man:pcre2pattern(3) for information about the supported regex language, and man:pcre2api(3) for information about the supported flags and extra_flags.

The regex will be compiled using <literal>PCRE2_UTF</literal> and possibly other flags, in addition to the flags supplied in flags.

If regex compilation fails, error will be set and error_offset point to error as an offset into pattern.

Added in version 0.76.

Parameters:
  • pattern – a regex pattern string

  • pattern_length – the length of pattern in bytes, or -1 if the string is NUL-terminated and the length is unknown

  • flags – PCRE2 compile flags

  • extra_flags

Methods

class Regex
jit(flags: int) bool

If the platform supports JITing, JIT compiles regex.

Parameters:

flags – PCRE2 JIT flags, or 0

substitute(subject: str, replacement: str, flags: int) str

See man:pcre2api(3) and man:pcre2_substitute(3) for more information.

Added in version 0.56.

Parameters:
  • subject – the subject string

  • replacement – the replacement string

  • flags – PCRE2 match flags