Numbers

Percentage

Matches percentage values with optional decimal and a trailing % sign.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^\\d+(\\.\\d+)?%$", "");
const input = "95%";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

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

Pattern

regexengine-agnostic
^\d+(\.\d+)?%$

Raw source: ^\d+(\.\d+)?%$

How it works

`^\d+` matches integer part. `(\.\d+)?` optional decimals. `%$` requires a trailing percent sign at end.

Examples

Input

95%

Matches

  • 95%

Input

99.9%

Matches

  • 99.9%

Input

100

No match

Common use cases

  • Statistics
  • Form inputs
  • Report parsing

Related patterns