Vulcan - 9 months ago 27

PHP Question

Consider the following regular expression, where

`X`

`X{n}|X{m}`

This regex would test for

`X`

`n`

`m`

Is there a regex quantifier that can test for an occurrence

`X`

`n`

`m`

Answer

There is no single quantifier that means "exactly m or n times". The way you are doing it is fine.

An alternative is:

```
X{m}(X{k})?
```

where `m < n`

and `k`

is the value of `n-m`

.