PatternRegex
Match a percentage
Find a percentage value, decimals included, wherever it appears in a report, review, or spreadsheet export.
Last updated
Matches
- Growth was 12.5% this year
- Discount: 20%
Doesn’t match
- Full percent sign %
- Discount was 20 percent off
Why it’s written this way
\d+ requires at least one digit before the sign, and the optional (?:\.\d+)? group allows a decimal point followed by more digits, so a whole number like 20% and a fractional one like 12.5% both match under the same rule.
The percent sign is required immediately after the digits, with no gap allowed, which keeps the pattern from wandering into unrelated numbers that merely sit near a % elsewhere in the text.
Edge cases to know
- →It won't catch percentages spelled out in words, such as '20 percent' — only the numeral-plus-symbol form counts.
- →A percentage written with a space before the sign, like '20 %', is missed for the same reason a bare '%' with nothing in front of it is: the digits and the symbol must be glued together.