Search code examples
regexnotepad++

Notepad++: Can I use regex to find some values and remove only one character instead of the whole pattern?


I want to use regex in notepad to find this pattern: "[0-9]+[\.][0-9]+[,][0-9]+" e.g. 1.010,80260 However from these kind of numbers I just want to remove the '.' , so the new value should be 1010,80260 . So far I can only replace the whole pattern. Is there a way to do it?

Thank you in advance!


Solution

  • You can make use of the \K meta escape since PCRE doesn't support variable width lookbehinds:

    regex:

    [0-9]+\K[\.](?=[0-9]+[,][0-9]+)
    
    • [0-9]+ - capture digits
    • \K - forget what we've captured
    • [\.] - capture a period; just \. can be used, no need for the char class brackets
    • (?=[0-9]+[,][0-9]+) - ahead of me should be digits followed by a comma and digits

    replace:

    Nothing

    enter image description here


    \K is bugged in Notepad++ so you could use this regex instead since you only care that at least one digit is behind the period:

    (?<=\d)\.(?=[0-9]+[,][0-9]+)