{n,}: at least n repetitions, with no upper bound
{n,} matches n or more repetitions of the preceding token. {0,} is the same as * and {1,} is the same as +, so the form earns its keep when n is two or higher.
At a glance
- Syntax
- {n,}
- Equivalent forms
- {0,} is *, and {1,} is +
- Upper bound
- none
- Greedy
- yes, the lazy form is {n,}?
- Whitespace
- {2, } with a space is not a quantifier, it is literal text
- Backtracking risk
- unbounded repetition inside another quantifier is the classic trigger
In detail
This is the quantifier for a minimum with no ceiling: at least three digits, at least two words, at least one but really more. Where n is zero or one it is just a longer spelling of a star or a plus, so a pattern using {1,} instead of + is usually a sign that the count was edited down and never simplified.
The whitespace rule catches people who format their patterns. A quantifier may not contain a space, so /a{2, }/ is not a quantifier at all: the braces fall through to literal text and the pattern searches for the seven characters a{2, } instead. It compiles, it runs, and it never matches the input you meant.
Being unbounded, this form is the one that shows up in reports about pattern denial of service. The problem is never the quantifier by itself; it is an unbounded repeat sitting inside another quantifier that can match the same characters. Putting a real ceiling on the count is usually the cheapest fix, because a bounded search space cannot blow up.
In practice a maximum is nearly always known. Nobody needs to accept a two thousand digit year or a filename of unlimited length, so replacing {3,} with {3,64} costs nothing, documents the real constraint and removes the risk at the same time.
Examples
"12 345 6789".match(/\d{3,}/g); // ["345", "6789"]The two digit run is skipped because it does not reach the minimum.
/a{2, }/.test("aaa"); // false
/a{2, }/.test("a{2, }"); // true, the braces are literal textThings that catch people out
- A space inside the braces stops it being a quantifier. /a{2, }/ compiles happily and searches for literal text, with nothing to indicate the change.
- {1,} and + are identical, and {0,} and * are identical. Writing the long form suggests a constraint that is not actually there.
- An unbounded count nested inside another quantifier is the standard catastrophic backtracking shape. Give it a real upper bound instead.
Try it: Regex Tester
Type a pattern and a test string, watch every match highlight as you go, read a plain English breakdown of each token, and check the numbered and named groups it captured.
Regex Tester
LOCAL · Browser-OnlyTest and debug regular expressions with live matching and highlights
Related Regex syntax
All regex syntax →{n,m}: bounded repetition between two counts
A bounded count is inclusive at both ends and greedy toward the maximum. JavaScript has no {,m} shorthand, and writing one produces literal text.
The * quantifier: zero or more, including nothing at all
The star quantifier succeeds even when it matches nothing, which is why a global match against it returns an empty string at almost every position.
Catastrophic backtracking: why a regex freezes a page
Nested quantifiers over overlapping characters make the work grow exponentially with input length. Here is the shape that causes it and the rewrites for it.
Lazy quantifiers: *?, +?, ?? and {n,m}?
A trailing question mark makes a quantifier prefer the shortest match. It fixes the overreaching tag pattern, and a negated class often fixes it better still.
Atomic groups in JavaScript: emulating them with a lookahead
JavaScript has no (?>...) and no possessive quantifiers. The lookahead and backreference pair gives you the same no backtracking behaviour.
The ^ anchor: start of string, or start of line
Where the caret matches with and without the m flag, why it consumes nothing, and the entirely different job it does inside a character class.
Tools for this
- Regex Tester Free online regex tester - test and debug regular expressions with live matching and highlights
- Regex Playground Regex playground with live match highlighting, named groups, find and replace, and shareable links