notepad++ find number greater than a specific number

可紊 提交于 2019-12-18 04:54:41

问题


I have logs with some random numbers.

What I want to do is find numbers greater than a specific number, eg : find all number > 1234567.

Can anybody help?


回答1:


A weird regex (not sure it's really usefull) :

\d{8,}|123456[8-9]|12345[7-9]\d|1234[6-9]\d{2}|123[5-9]\d{3}|12[4-9]\d{4}|1[3-9]\d{5}|[2-9]\d{6}\b

It works only for the number 1234567 you have to modify it for another number.




回答2:


You could use Notepad++'s Python Script plugin. Not the best solution, but it works!

  1. Install Python Script plugin, from Plugin Manager or from the official website.
  2. Then go to Plugins > Python Script > New Script. Choose a filename for your new file (eg find_numbers.py) and copy the code that follows.
  3. Run Plugins > Python Script > Scripts > find_numbers.py and a new window will show the matched numbers.
from re import finditer

number = 1234567

console.clear()
console.show()
content = editor.getText()
for row, line in enumerate(content.split('\n')):
    for m in re.finditer(r'[0-9]+', line):
        if int(m.group(0)) > number:
            console.write('row %d, col %d-%d: %s\n' % (row, m.start(), m.end(), m.group(0)))

So for example take this text:

This is a test 1234568
with asome pretty big numbers 0 1234567
Can anybody help?
999999999999 99999999
123

The above solution will return you this:

row 0, col 15-22: 1234568
row 3, col 0-12: 999999999999
row 3, col 13-21: 99999999

You can obviously change the script to output the information in any way you prefer.



来源:https://stackoverflow.com/questions/21406141/notepad-find-number-greater-than-a-specific-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!