【问题标题】:notepad++ find number greater than a specific numbernotepad++ 查找大于特定数字的数字
【发布时间】:2014-02-19 18:48:47
【问题描述】:

我有一些随机数的日志。

我想要做的是找到大于特定数字的数字,例如:find all number > 1234567.

有人可以帮忙吗?

【问题讨论】:

  • 我认为不可能,因为数字计数可以是任何东西。您可以在正则表达式中进行数值范围检查,但鉴于您的情况上限是无穷大,我怀疑使用正则表达式是否可能甚至可行
  • 如果数字在行首,您可以对行进行排序。如果没有,您可以先使用正则表达式搜索和替换将它们移到那里。请记住,虽然它不是数字排序,所以你会在 2 之前得到 10,依此类推。但这可能会有所帮助。

标签: find notepad++


【解决方案1】:

您可以使用 Notepad++ 的 Python 脚本插件。不是最好的解决方案,但它有效!

  1. 从插件管理器或 official website 安装 Python 脚本插件。
  2. 然后转到插件 > Python 脚本 > 新脚本。为您的新文件选择一个文件名(例如 find_numbers.py)并复制下面的代码。
  3. Run Plugins > Python Script > Scripts > find_numbers.py 和一个新窗口将显示匹配的数字。
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)))

所以以这个文本为例:

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

上述解决方案将返回:

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

您显然可以更改脚本以任何您喜欢的方式输出信息。

【讨论】:

    【解决方案2】:

    一个奇怪的正则表达式(不确定它是否真的有用):

    \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
    

    它仅适用于号码1234567,您必须将其修改为另一个号码。

    【讨论】:

      猜你喜欢
      • 2023-03-21
      • 1970-01-01
      • 2013-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      相关资源
      最近更新 更多