Repetition

A quantifier is used to repeat an element; three of the quantifiers have already been introduced: *, +, and ?. The quantifiers are as follows:

Description

Character

Example

The preceding character repeated zero or more times

*

'abc'-match 'a*'

'abc'-match '.*'

The preceding character repeated one or more times

+

'abc'-match 'a+'

'abc'-match '.+'

Optional character

?

'abc' -match 'ab?c'

'ac' -match 'ab?c'

A fixed number of characters

{exactly}

'abbbc' -match 'ab{3}c'

A number of characters within a range

{min,max}

'abc' -match 'ab{1,3}c'

'abbc' -match 'ab{1,3}c'

'abbbc' -match 'ab{1,3}c'

No less than a number of characters

{min,}

'abbc' -match 'ab{2,}c'

'abbbbbc' -match 'ab{2,}c'

Each *, +, and ? can be described using a curly brace notation:

  • * is the same as {0,}
  • + is the same as {1,}
  • ? is the same as {0,1}

It is extremely uncommon to find examples where the functionality of special characters is replaced with curly braces. It is equally uncommon to find examples where the quantifier {1} is used as it adds unnecessary complexity to an expression.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset