pyrit.prompt_converter.WordRegexSelectionStrategy#

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

Bases: WordSelectionStrategy

Selects words that match a regex pattern.

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

Initializes the word regex selection strategy.

Parameters:

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

Methods

__init__(*, pattern)

Initializes the word regex selection strategy.

select_range(*, text[, word_separator])

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

select_words(*, words)

Selects words that match the regex pattern.

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

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