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).
Python (re) code
pyPython
import re
pattern = re.compile(r"^\d+(\.\d+)?%$")
input_text = "95%"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^\d+(\.\d+)?%$`)
input := `95%`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
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
100No match
—Common use cases
- •Statistics
- •Form inputs
- •Report parsing
Related patterns
US Currency (USD)
NumbersMatches USD currency amounts with optional $ sign, thousands separators, and cents.
Decimal Number
NumbersMatches decimal numbers, including integers and negatives.
Binary Number Literal
NumbersMatch binary number literals like `0b1010` or `0B11110000`.
Float / Scientific Number
NumbersMatch floating-point and scientific-notation numbers including `1.5`, `.25`, `1e10`, `-3.14E-2`.