pregex.core.quantifiers

Every class within this module is used to declare that a pattern is to be matched a number of times, with each class representing a slightly different pattern-repetition rule.

Classes & methods

Below are listed all classes within pregex.core.quantifiers along with any possible methods they may possess.

class pregex.core.quantifiers.AtLeast(pre: Union[Pregex, str], n: int, is_greedy: bool = True)[source]

Matches the provided pattern a minimum number of times.

Parameters
  • pre (Pregex | str) – The pattern that is to be quantified.

  • n (int) – The minimum number of times that the provided pattern is to be matched.

  • is_greedy (bool) – Determines whether to declare this quantifier as greedy. When declared as such, the regex engine will try to match the expression as many times as possible. Defaults to True.

Raises
  • InvalidArgumentTypeException

    • Parameter pre is neither a Pregex instance nor a string.

    • Parameter n is not an integer.

  • InvalidArgumentValueException – Parameter n has a value of less than zero.

  • CannotBeRepeatedException – Parameter pre represents a non-repeatable pattern.

class pregex.core.quantifiers.AtLeastAtMost(pre: Union[Pregex, str], n: int, m: Optional[int], is_greedy: bool = True)[source]

Matches the provided expression between a minimum and a maximum number of times.

Parameters
  • pre (Pregex | str) – The pattern that is to be quantified.

  • n (int) – The minimum number of times that the provided pattern is to be matched.

  • m (int) – The maximum number of times that the provided pattern is to be matched.

  • is_greedy (bool) – Indicates whether to declare this quantifier as greedy. When declared as such, the regex engine will try to match the expression as many times as possible. Defaults to True.

Raises
  • InvalidArgumentTypeException

    • Parameter pre is neither a Pregex instance nor a string.

    • Parameter n is not an integer.

    • Parameter m is neither an integer nor None.

  • InvalidArgumentValueException

    • Either parameter n or m has a value of less than zero.

    • Parameter n has a greater value than that of parameter m.

  • CannotBeRepeatedException – Parameter pre represents a non-repeatable pattern while parameter m has been set to a value of greater than 1.

Note
  • Parameter is_greedy has no effect in the case that n equals m.

  • Setting m equal to None indicates that there is no upper limit to the number of times the pattern is to be repeated.

class pregex.core.quantifiers.AtMost(pre: Union[Pregex, str], n: Optional[int], is_greedy: bool = True)[source]

Matches the provided pattern up to a maximum number of times.

Parameters
  • pre (Pregex | str) – The pattern that is to be quantified.

  • n (int) – The maximum number of times that the provided pattern is to be matched.

  • is_greedy (bool) – Indicates whether to declare this quantifier as greedy. When declared as such, the regex engine will try to match the expression as many times as possible. Defaults to True.

Raises
  • InvalidArgumentTypeException

    • Parameter pre is neither a Pregex instance nor a string.

    • Parameter n is neither an integer nor None.

  • InvalidArgumentValueException – Parameter n has a value of less than zero.

  • CannotBeRepeatedException – Parameter pre represents a non-repeatable pattern while parameter n has been set to a value of greater than 1.

Note

Setting n equal to None indicates that there is no upper limit to the number of times the pattern is to be repeated.

class pregex.core.quantifiers.Exactly(pre: Union[Pregex, str], n: int)[source]

Matches the provided pattern an exact number of times.

Parameters
  • pre (Pregex | str) – The pattern that is to be quantified.

  • n (int) – The exact number of times that the provided pattern is to be matched.

Raises
  • InvalidArgumentTypeException

    • Parameter pre is neither a Pregex instance nor a string.

    • Parameter n is not an integer.

  • InvalidArgumentValueException – Parameter n has a value of less than zero.

  • CannotBeRepeatedException – Parameter pre represents a non-repeatable pattern while parameter n has been set to a value of greater than 1.

class pregex.core.quantifiers.Indefinite(pre: Union[Pregex, str], is_greedy: bool = True)[source]

Matches the provided pattern zero or more times.

Parameters
  • pre (Pregex | str) – The pattern that is to be quantified.

  • is_greedy (bool) – Indicates whether to declare this quantifier as greedy. When declared as such, the regex engine will try to match the expression as many times as possible. Defaults to True.

Raises
  • InvalidArgumentTypeException – Parameter pre is neither a Pregex instance nor a string.

  • CannotBeRepeatedException – Parameter pre represents a non-repeatable pattern.

class pregex.core.quantifiers.OneOrMore(pre: Union[Pregex, str], is_greedy: bool = True)[source]

Matches the provided pattern one or more times.

Parameters
  • pre (Pregex | str) – The pattern that is to be quantified.

  • is_greedy (bool) – Indicates whether to declare this quantifier as greedy. When declared as such, the regex engine will try to match the expression as many times as possible. Defaults to True.

Raises
  • InvalidArgumentTypeException – Parameter pre is neither a Pregex instance nor a string.

  • CannotBeRepeatedException – Parameter pre represents a non-repeatable pattern.

class pregex.core.quantifiers.Optional(pre: Union[Pregex, str], is_greedy: bool = True)[source]

Matches the provided pattern once or not at all.

Parameters
  • pre (Pregex | str) – The pattern that is to be quantified.

  • is_greedy (bool) – Indicates whether to declare this quantifier as greedy. When declared as such, the regex engine will try to match the expression as many times as possible. Defaults to True.

Raises

InvalidArgumentTypeException – Parameter pre is neither a Pregex instance nor a string.