liveBook · Manning

One-or-more quantifier

As explained in The Quick Python Book, Fourth Edition

A one-or-more quantifier requires the preceding regular-expression element to occur at least once and permits additional occurrences.

The `+` quantifier repeats the regular-expression element immediately before it one or more times. It requires at least one occurrence, while allowing additional occurrences. section 16.4

Applied to a character class, the quantifier changes the match from one character to a nonempty sequence:

  • `[-a-zA-Z]` matches one hyphen or letter. section 16.4
  • `[-a-zA-Z]+` matches names such as `Kenneth`, `McDonald`, and `Perkin-Elmer`. section 16.4
  • The same pattern can also match non-names such as `---` or `-a-b-c-`; additional validation may be needed. section 16.4
[-a-zA-Z]+

Inspect the compact pattern used to require one or more letters or hyphens. section 16.4

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Defines immediate-predecessor repetition and demonstrates character-class matching, but does not develop engine internals.
Examples
Demonstrates names, hyphenated names, overmatching strings, and Python `re` patterns for contact records.
What it assumes
Assumes familiarity with regular-expression character classes and grouped patterns.
What you can do after
Apply the quantifier in Python `re` patterns to match one or more characters or repeated subpatterns.
How it connects
Connects character classes, regular expressions, optional groups, and bounded repetition.

Also explained in

Compare how 2 books explain one-or-more quantifier →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.