如何使用 notepad++ 从一串数字中提取 4 位数字

如何使用 notepad++ 从一串数字中提取 4 位数字

假设我有字符串:

[(3749.0, 77.19), (3699.0, 86.11), (3648.0, 90.87), (3623.0, 81.35), (3608.0, 88.06), (3601.0, >97.73), (3576.0, 79.31), (3558.0, 84.12), (3551.0, 94.65), (3525.0, 82.88), (3511.0, 87.48),
(3500.0, 97.57), (3450.0, 91.18)]

我怎样才能获得前几组 4 位数字的输出:

3749.0
3699.0
3648.0
3623.0
etc.

非常感谢您的任何反馈。

答案1

做这个 :

  • Ctrl+F
  • 转至标记选项卡
  • 输入“查找内容”:\b\d{4}\b并确保选中“正则表达式”。若要同时选择点后的数字,请使用表达式 \b\d{4}\.\d\b
  • 按“标记全部”
  • 按复制标记的文本
  • 将剪贴板粘贴到文本文档中,包含所有选定的数字,每行一个。

在此处输入图片描述

答案2

  • Ctrl+H
  • 找什么:(?:\[|\G).*?\((\d{4}\.\d)(?:, \d+\.\d+\)\])?
  • 替换为:$1\n$1\r\n取决于平台
  • 打钩 环绕
  • 选择 正则表达式
  • 打钩 . matches newline
  • Replace all

解释:

(?:\[|\G)       # non capture group, opening square bracket OR restat from last match position
.*?             # 0 or more any character, not greedy
\(              # opening parenthesis
(               # start group 1
    \d{4}           # 4 digits
    \.              # a dot
    \d              # a digit
)               # end group 1
(?:             # non capture group
    , \d+\.\d+      # a comma, a space, 1 or more digits, a dot, 1 or more digits)
    \)              # closing parenthesis
    \]              # closing square bracket
)?              # end group, optional

截图(之前):

在此处输入图片描述

截图(之后): 在此处输入图片描述

相关内容