[prev] [index] [next]

Repetition

We can specify repetitions of patterns
  • p* denotes zero or more repetitions of p
  • p+ denotes one or more repetitions of p
  • p? denotes zero or one occurence of p
E.g. [0-9]+ matches any sequence of digits (i.e. matches integers)

E.g. [-'a-zA-Z]+ matches any sequence of letters/hyphens/apostrophes
(this pattern could be used to match words in a piece of English text, e.g. it's, John, ...)

E.g. [^X]*X matches any characters up to and including the first X