Pattern library / Numbers & Codes
Regex to Match Percentage Values
Accepts 50, 50%, 50.5% and rejects out-of-range values. Useful for GA4 metric validation.
How the pattern works
100(\.0{1,2})?— 100 with optional .0 or .00.\d{1,2}(\.\d{1,2})?— 0-99 with up to 2 decimals.%?— optional percent sign.- Allows up to 2 decimal places; change
{1,2}for more precision.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
50% | Match | integer percent | Try → |
50.5 | Match | decimal without % | Try → |
100 | Match | max value | Try → |
100.00 | Match | max with decimals | Try → |
100.5 | No match | over 100 | Try → |
150% | No match | over 100 | Try → |
Where to use it
JavaScript
const re = /^(100(\.0{1,2})?|\d{1,2}(\.\d{1,2})?)%?$/;
re.test('50.5%'); // true
Python
import re
re.match(r'^(100(\.0{1,2})?|\d{1,2}(\.\d{1,2})?)%?$', '50.5%')
Common mistakes
Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
FAQ
Related patterns
Regex Number in Range 1-100 — Match Values Between Limits · Extract Numbers from String — Regex + Examples · Currency Regex - Match Prices & Money Amounts
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.