From a text file I have to find all the line which have containing percentages (numbers + % or percent) for this I have created a regex but it doesnot work correctly.
regex string: \b(\d+(%|(percent)))\b
and my inputs are
for 1st two cases it is not matching but for 3rd and 4th it works.
My requirement is to identfy the line which having numbers + % or percent and around it there should be no alphabate or number
The word boundary after % prevents it from matching before non-word chars.
Use
\b\d+(?:%|percent\b)
See the regex demo
The pattern matches:
\b - a leading word boundary\d+ - 1+ digits(?:%|percent\b) - one of the two alternatives:
% - a percentage signpercent\b - word percent followed with a word boundary.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With