Search code examples
regexnotepad++

How to Bookmark Normal and Decimal Percentage Numbers in Notepad++?


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|$)

Solution

  • 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+)?%