Advertisement

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.

The pattern
^(100(\.0{1,2})?|\d{1,2}(\.\d{1,2})?)%?$
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
50%Matchinteger percentTry →
50.5Matchdecimal without %Try →
100Matchmax valueTry →
100.00Matchmax with decimalsTry →
100.5No matchover 100Try →
150%No matchover 100Try →

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.
Open the regex tester →

FAQ

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.