JavaScript RegExp + Quantifier

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

What Is +?

The + quantifier means one or more of the previous token. Turn a single digit \d into a full number with \d+, or a word character into a whole word with \w+. It needs at least one match—unlike *, which allows zero.

Remember
token+     → one or more of token  (same as {1,})

/\d+/  on "item42"  → "42"
/\w+/  on "Hi!"     → "Hi"
/a+/   on ""        → null   (+ needs at least one)

greedy by default; use +? for lazy (minimal) matching
UsePrefer
Digit runs/\d+/g
Word runs/\w+/g
Zero allowed?* instead

How to Use +

Place + right after the token you want to repeat.

  1. Choose the token: a character, class, metacharacter, or group.
  2. Add + immediately after it (e.g. \d+ or (ha)+).
  3. Add g when you want every run, not just the first.
  4. Use +? when greedy matching grabs too much.
PieceRequired?Role
Preceding tokenYesWhat gets repeated
+YesOne or more (greedy)
+?OptionalOne or more (lazy)
g flagOptionalFind every run in the string

Pseudocode

Pseudocode
re = /token+/

find "token" once (required)
keep matching "token" while it still fits
return the whole run

if "token" never appears → no match

Cheat Sheet

Keep these + facts handy.

TopicDetail
MeaningOne or more of previous token
Shorthand+ = {1,}
vs ** allows zero; + does not
vs ?? is zero or one
Greedy / lazy+ max; +? min
Groups(ab)+ repeats the whole group
StandardES3+ (universal)

Live Preview

Run common + patterns and see what matches.

Browser demo of + — same idea as the examples below.

Result
"a1b22c333".match(/\d+/g)
→ ["1", "22", "333"]

/* + gathers consecutive digits into runs */

JavaScript Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Extract Numbers with \d+

Match runs of digits; add g for every run.

JavaScript
const text = "order 12 items for $49.99";

console.log(text.match(/\d+/));   // ["12"] — first run only
console.log(text.match(/\d+/g));  // ["12", "49", "99"]
Try It Yourself

How It Works

  1. One digit is not enough. \d alone matches a single digit; \d+ keeps going.
  2. First run. Without g, match returns only "12".
  3. All runs. With g, you get every consecutive digit group.
  4. Dots break runs. In 49.99, the . splits the match into 49 and 99.

Example 2 — Collapse Whitespace with \s+

Treat one or more spaces as a single unit and replace them.

JavaScript
const messy = "too    many   spaces";
const clean = messy.replace(/\s+/g, " ");

console.log(clean);  // "too many spaces"
Try It Yourself

How It Works

  1. Match a run. \s+ finds one or more whitespace characters together.
  2. Replace each run. Every match becomes a single space.
  3. Global flag. g cleans every gap in the string, not just the first.
  4. Result. Multiple spaces collapse into one without a manual loop.

Example 3 — Greedy + vs Lazy +?

See how greediness changes what gets matched between tags.

JavaScript
const html = "<b>bold</b> and <i>italic</i>";

console.log(html.match(/<.+>/g));
// ["<b>bold</b> and <i>italic</i>"] — greedy spans too far

console.log(html.match(/<.+?>/g));
// ["<b>", "</b>", "<i>", "</i>"] — lazy stops early
Try It Yourself

How It Works

  1. Greedy default. .+ takes as much as possible, so it runs to the last >.
  2. One big match. That often swallows more text than you want.
  3. Lazy +?. Matches the shortest run that still works.
  4. Separate tags. Each <…> becomes its own match.

Edge Cases & Pitfalls

Check these before relying on +.

minimum

Needs at least one

/a+/ fails on "". If zero is allowed, use *.

precedence

ab+ ≠ (ab)+

ab+ repeats only b. Use parentheses when the whole sequence must repeat.

greedy

Greedy can overshoot

.+ often matches too much in nested text. Try +? for the shortest valid run.

decimals

Floats need more than \d+

49.99 is two digit runs. Use something like \d+\.\d+ for one decimal number.

Browser & Runtime Support

The + quantifier is part of core JavaScript regular expression syntax (ES3+).

✓ Baseline · ES3+

RegExp + quantifier

Supported in every browser and Node.js version. Use + for one-or-more repetition of any token or group.

99% Universal syntax
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
+ Excellent

Bottom line: Safe everywhere. + is the standard way to match runs of one or more characters.

Performance Notes

ApproachCostBest for
/\d+/gLinear over inputExtracting runs
/\s+/g replaceLinearWhitespace cleanup
Nested (a+)+Can explodeAvoid on untrusted input

Simple + on a class or metacharacter is fast. Nested greedy quantifiers like (a+)+ can cause catastrophic backtracking—keep patterns simple on untrusted text.

Key Takeaways

  • Role: + means one or more of the previous token.
  • Shorthand: + equals {1,}.
  • Lazy: use +? when greedy matching goes too far.
  • vs *: use * only when zero matches should succeed.

One line: use + when you need a run of one or more characters—digits, words, spaces, or a whole group.

Frequently Asked Questions

The + quantifier means one or more of the preceding token. For example, \d+ matches a sequence of one or more digits. It requires at least one match—unlike *, which allows zero.
+ requires at least one repetition of the previous token. * allows zero or more. So /a+/ fails on an empty string, but /a*/ succeeds (matching zero a characters).
Yes. The + quantifier is shorthand for {1,}, which means at least one and no upper limit. Both are greedy by default in JavaScript.
+ is greedy—it matches as many characters as possible. +? is lazy (non-greedy)—it matches as few as possible while still satisfying the one-or-more rule.
Yes. When placed after a group like (ab)+, it repeats the entire group one or more times. Example: (ha)+ matches ha, haha, hahaha.
The + quantifier is core JavaScript regex syntax since ES3. It works in every browser and Node.js version without polyfills.

Next: (?=...) positive lookahead

Learn how (?=...) requires text to follow without consuming it.

(?=...) tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful