pyrit.prompt_converter.WordRegexSelectionStrategy#

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

Bases: WordSelectionStrategy

Selects words that match a regex pattern.

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

Initialize the word regex selection strategy.

Parameters:

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

Methods

__init__(*, pattern)

Initialize the word regex selection strategy.

select_range(*, text[, word_separator])

Select a character range by first selecting words, then converting to character positions.

select_words(*, words)

Select words that match the regex pattern.

select_words(*, words: List[str]) List[int][source]#

Select words that match the regex pattern.

Parameters:

words (List[str]) – The list of words to select from.

Returns:

The list of indices where words matched the pattern.

Return type:

List[int]