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 match = input.match(re);
console.log(match ? match[0] : null);

Uses `String.prototype.match`, which returns the first match or null.

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