0

论坛成员,

NotePad++ 通用表达式是否可以提取“X”数量的文本和夹在其之间的 \r\n 位于上方和下方的条目的行?以下是视觉示例作为辅助:

UNWANTED "X" amount of text above
\r\n
\r\n
\r\n
\r\n
"X" amount of text and rows sandwiched in between four entries of \r\n below and above
\r\n
\r\n
\r\n
\r\n
UNWANTED "X" amount of text below

我的目标是让通用表达式仅提取位于四个 \r\n 值之间的任何数量的文本和行,以及后面要说的所有 UNWANTED TEXT。下面是我需要如何将数据从剪贴板粘贴到新文本文件的示例:

"X" amount of text and rows in sandwiched in between four entries of \r\n below and above
\r\n
\r\n
\r\n
"X" amount of text and rows in sandwiched in between four entries of \r\n below and above
\r\n
\r\n
\r\n
"X" amount of text and rows in sandwiched in between four entries of \r\n below and above
\r\n
\r\n
\r\n
"X" amount of text and rows in sandwiched in between four entries of \r\n below and above

不同之处在于删除了所有不需要的文本,剩下的只是最初嵌套在 \r\n 的四个值中的数据现在嵌套在 \r\n 的三个值中。任何帮助将不胜感激。

4

1 回答 1

0

转到Search > Replace菜单(快捷键CTRL+ H)并执行以下操作:

  1. 找什么:

    .+?(?:\r\n){5}(.+(?:\r\n){4})\r\n.+(?:\r\n)?
    
  2. 代替:

    $1
    
  3. 选择单选按钮“正则表达式”

  4. 然后按Replace All

这将转换以下文件:

UNWANTED "X" amount of text above




"X" amount of text and rows sandwiched in between four entries of \r\n below and above




UNWANTED "X" amount of text below

至:

"X" amount of text and rows sandwiched in between four entries of \r\n below and above



(we keep only 3 empty lines)
于 2013-10-29T00:30:26.760 回答