pyrit.prompt_converter.RegexSelectionStrategy#

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

Bases: TextSelectionStrategy

Selects text based on the first regex match.

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

Initialize the regex selection strategy.

Parameters:

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

Methods

__init__(*, pattern)

Initialize the regex selection strategy.

select_range(*, text)

Select the range of the first regex match.

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

Select 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]