0

I'm trying to bookmark lines that contain percentage numbers in Notepad++. Specifically, I want to bookmark both whole number percentages (like 9%) and decimal percentages (like 4.5%).

for example I have following list:

VitrtertWW
44.98%
Liertertde
32.52%
Ltettth
Ltertrth9%
Mhrhrththw
4.5%
1992Q2
/////////////////////////

I want to move all percentage numbers to next line.
following regex is working good:

Find: \d+\.\d+%
Replace: \n$0

but my regex have a problem. It just move decimal percentage numbers to next line and normal percentage numbers not move to next line.
how to fix this problem?

I tried following regular expressions too but not working:

(?<!\d)\d%(?!\d)
(|\s)\d%(\s|$)
2
  • 1
    Make the "dot and digits after" part optional? \d+(\.\d+)?%
    – CBroe
    Commented Jun 28 at 6:46
  • @CBroe yes it working - send as answer that i can accept your answer Commented Jun 28 at 6:50

2 Answers 2

2

You could make the decimal part optional:

\d+(?:\.\d+)?%
  • (?: - start of non-capturing
    • \.\d+ - the decimal part
  • ) - end of the non-capturing part
  • ? - 0 or 1 matches of the previous match (the non-capturing part)

Demo

0
1

It just move decimal percentage numbers to next line and normal percentage numbers not move to next line.

That's because your find pattern demands that there is a dot and digits after it. Simply make that part of the pattern optional:

\d+(\.\d+)?%

Not the answer you're looking for? Browse other questions tagged or ask your own question.