JavaScript / ECMAScript

USD Currency (Inline) in JS

Match US dollar amounts inline in text: `$1,234.56`, `$99`, `$1,000,000.00`.

Try it in the JS tester →

Pattern

regexJS
\$\d{1,3}(?:,\d{3})*(?:\.\d{2})?   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("\\$\\d{1,3}(?:,\\d{3})*(?:\\.\\d{2})?", "g");
const input = "Total $1,234.56 plus tax of $99";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

\$ matches the literal dollar sign. \d{1,3} matches the first 1–3 digits. (?:,\d{3})* matches additional thousands groups (comma + 3 digits). (?:\.\d{2})? optionally matches a decimal portion with exactly two digits (cents).

Examples

Input

Total $1,234.56 plus tax of $99

Matches

  • $1,234.56
  • $99

Input

Bonus $1,000,000.00 awarded

Matches

  • $1,000,000.00

Input

no money mentioned

No match

Same pattern, other engines

← Back to USD Currency (Inline) overview (all engines)