JavaScript RegExp + Quantifier

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
One or more

What You’ll Learn

The + quantifier repeats the previous token one or more times. It is one of the most common tools in regex: turn a single digit \d into a full number \d+, or a letter into a whole word with \w+. Master + and you can match runs of characters efficiently.

01

+

One or more

02

{1,}

Same meaning

03

Greedy

Max match

04

+?

Lazy mode

05

(ab)+

Group repeat

06

+ g

All runs

Introduction

A single metacharacter like \d matches exactly one digit. Real data often contains runs of characters: phone numbers, prices, words, and repeated punctuation. The + quantifier solves this by saying “match the previous item again and again, at least once.”

For example, /\d+/ on "item42" matches "42", not just "4". Without +, you would need to write longer patterns or loop in JavaScript. With +, one concise regex captures the entire number token.

Understanding the + Quantifier

Place + immediately after a character, metacharacter, class, or group. It is greedy by default: the engine takes as many repetitions as possible while still allowing the rest of the pattern to succeed.

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

"a".match(/a+/);   // ["a"]
"".match(/a+/);    // null — + requires at least one

Shorthand: + equals {1,} (minimum one, no maximum). Unlike *, which allows zero matches, + fails when the preceding token is absent.

💡
Beginner Tip

Add the global g flag when you want every run in a string, not just the first. "a1b22".match(/\d+/) returns only ["1"]; add g to get ["1", "22"].

How to Use the + Quantifier

Attach + to tokens you want to repeat, combine with anchors for validation, or use lazy +? for minimal matches:

JavaScript
/\d+/g;                    // all digit runs
/\w+/g;                    // all word runs
/\s+/g;                    // whitespace blocks
/(ha)+/g;                  // ha, haha, hahaha
/<.+?>/g;                  // lazy tag match
/^\d+$/;                   // whole string is digits

Use test() for presence checks, match() to extract runs, and replace(/\s+/g, " ") to collapse repeated spaces.

📝 Syntax

JavaScript
token+           // one or more of token
\d+              // one or more digits
\w+              // one or more word chars
(group)+         // repeat entire group
token+?          // lazy — as few as possible
token{1,}        // equivalent to +

Common patterns

  • /\d+/g — extract all number tokens from text.
  • /\w+/g — pull words from a sentence.
  • /\s+/g — find whitespace runs for splitting or cleanup.
  • /^\d+$/ — validate a string contains only digits.
  • /(https?:\/\/\S+)/g — capture URL-like runs.

⚡ Quick Reference

GoalPattern / API
One or more digits\d+
One or more words chars\w+
All runs in string/pattern+/g
Repeat a group(ab)+
Lazy (minimal) match+?
Longhand form{1,}

📋 + vs * vs ?

The three basic repetition quantifiers and when to use each.

+
token+

One or more — requires at least one

*
token*

Zero or more — optional repetition

?
token?

Zero or one — makes token optional

On ""
/a+/

Fails — + needs at least one a

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Examples cover digit runs, word extraction, whitespace cleanup, greedy vs lazy matching, and repeating groups.

📚 Getting Started

Match runs of characters with +.

Example 1 — Extract Numbers with \d+

Find every sequence of one or more digits.

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

\d+ greedily consumes consecutive digits. The dot in 49.99 breaks the run, so you get separate matches 49 and 99. See also the \d metacharacter page.

📈 Practical Patterns

Words, whitespace, and advanced repetition.

Example 2 — Extract Words with \w+

Pull word-like tokens from a sentence.

JavaScript
const sentence = "Hello, regex world!";

const words = sentence.match(/\w+/g);
console.log(words); // ["Hello", "regex", "world"]
Try It Yourself

How It Works

\w matches letters, digits, and underscore. The + groups consecutive word characters into tokens. Punctuation and spaces break the runs.

Example 3 — Collapse Whitespace with \s+

Replace multiple spaces or tabs with a single space.

JavaScript
const messy = "too    many   spaces";

const clean = messy.replace(/\s+/g, " ");
console.log(clean); // "too many spaces"
Try It Yourself

How It Works

\s+ matches one or more whitespace characters as a single unit. Replacing each run with one space normalizes the string without manual loops.

Example 4 — Greedy + vs Lazy +?

See how greediness affects tag-like matching.

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>"]
Try It Yourself

How It Works

Greedy + takes as much as possible, so .+ runs from the first < to the last >. Lazy +? stops at the earliest valid point, matching each tag separately.

Example 5 — Repeat a Group with (ha)+

Apply + to a captured group for repeated sequences.

JavaScript
const laughs = ["ha", "haha", "hahaha", "ho"];

laughs.forEach((s) => {
  console.log(s, /(ha)+/.test(s));
});
// ha     true
// haha   true
// hahaha true
// ho     false
Try It Yourself

How It Works

(ha)+ repeats the entire group one or more times. "hahaha" is three ha units. "ho" does not start with ha, so the test fails.

🚀 Common Use Cases

  • Number extraction — pull integers or digit runs with \d+.
  • Word tokenization — split sentences into words via \w+ and g.
  • Whitespace cleanup — normalize spaces, tabs, and newlines with \s+.
  • URL and path segments — match non-space runs like \S+ for tokens.
  • Validation — require one-or-more with /^[a-z]+$/i for letter-only fields.
  • Repeated patterns — match laughter, separators, or rhythmic text with grouped +.

Important Considerations

  • At least one+ fails when the preceding token is missing; use * if zero is allowed.
  • Greedy default+ may match more than you expect; try +? for minimal runs.
  • Global flag — without g, match() returns only the first run.
  • Precedenceab+ repeats only b; use (ab)+ to repeat both letters.
  • Not unbounded safety — catastrophic backtracking can occur with nested quantifiers like (a+)+ on hostile input.
  • Decimal numbers\d+ alone does not match 49.99 as one token; use \d+\.\d+.

🧠 How the + Quantifier Works

1

Match first token

The engine matches the preceding item once—the minimum for +.

Start
2

Repeat greedily

While the next character still matches the token, keep consuming it.

Greedy
3

Stop at boundary

When the next character fails, the quantifier stops and later pattern parts continue.

Boundary
4

Backtrack if needed

If the rest of the pattern fails, the engine may give back characters and retry shorter runs.

📝 Notes

  • + is shorthand for {1,}—at least one, no upper limit.
  • Previous topic: (?!...) negative lookahead.
  • Next topic: (?=...) positive lookahead.
  • See \d for digit matching with +.
  • See \s for whitespace runs.
  • Lazy variants: *? and ?? follow the same minimal-match idea as +?.

Browser & Runtime Support

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

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.

Conclusion

The + quantifier matches one or more of the previous token—turning single-character patterns into powerful run matchers like \d+, \w+, and \s+. It is greedy by default, equivalent to {1,}, and essential for extraction and validation.

Remember to add g for all matches, use +? when greedy matching goes too far, and wrap groups in parentheses when the whole group should repeat. Next, learn (?=...) positive lookahead.

💡 Best Practices

✅ Do

  • Use + when at least one repetition is required
  • Add g to collect every run in a string
  • Use (group)+ when the whole sequence repeats
  • Try +? for minimal matching in nested text
  • Prefer \d+ over manual digit loops in JavaScript

❌ Don’t

  • Use + when zero matches should succeed—use *
  • Forget parentheses: ab+ is not the same as (ab)+
  • Assume one + match equals the whole string without anchors
  • Nested greedy quantifiers on untrusted input without care
  • Match floats with \d+ alone—add \.\d+

Key Takeaways

Knowledge Unlocked

Five things to remember about the RegExp + quantifier

Match one or more repetitions with confidence.

5
Core concepts
📈 02

{1,}

Same rule.

Shorthand
📄 03

Greedy

Max first.

Default
🔒 04

+?

Minimal run.

Lazy
🚀 05

+ g

All runs.

Extract

❓ 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.
Did you know?

The + quantifier is so common that many developers learn \d+ before they learn what \d alone does. Under the hood, + always applies to exactly one preceding token—parentheses let you treat a group as that single token for repetition.

Continue to ?= positive lookahead

Learn how to require specific following text without consuming it.

?= quantifier 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.

6 people found this page helpful