Search code examples
regexnotepad++

Notepad++ replace specific number with up to it's first 4 digit


I want to find those number which contains more than 5 digits and replace it with first 4 digits. Used below Regex to find number which contains more than 5 digits.

[0-9]{5,}

How Can I achieve blow output?

99999999 -> this will replace with 9999
12345.66 -> this will replace with 1234.66 
1234 -> Remains unchanged

Solution

  • This one should do it:

    enter image description here

    The regex

    ([0-9]{4})[0-9]+
    
    • takes the four numbers as first (and only) group
    • requires at lease one more number behind
    • replaces the complete match with the first (and only) group