pyrit.prompt_converter.RegexSelectionStrategy#

class RegexSelectionStrategy(*, pattern: str | Pattern)[source]#

Bases: TextSelectionStrategy

Selects text based on the first regex match.

__init__(*, pattern: str | Pattern) None[source]#

Initializes the regex selection strategy.

Parameters:

pattern (Union[str, Pattern]) – The regex pattern to match.

Methods

__init__(*, pattern)

Initializes the regex selection strategy.

select_range(*, text)

Selects the range of the first regex match.

select_range(*, text: str) tuple[int, int][source]#

Selects the range of the first regex match.

Parameters:

text (str) – The input text to select from.

Returns:

A tuple of (start_index, end_index) of the first match,

or (0, 0) if no match found.

Return type:

tuple[int, int]