有没有办法断掉与字符串模式匹配的行,但前提是该模式位于匹配的字符串之间?

有没有办法断掉与字符串模式匹配的行,但前提是该模式位于匹配的字符串之间?

我正在使用下面的代码来断掉符合模式的行:

找什么:

([0-9]) ([A-Z])

用。。。来代替: \1\n\2

以便 …

Super Bowl 3,1:56.2 Armbro Goal 3,1:54.3

…变成

Super Bowl 3,1:56.2 
Armbro Goal 3,1:54.3

但是我必须手动替换每个实例,因为我有成千上万行,如果我使用全部替换,它会在我不想断开的区域断开行。

具体来说,我想断开与位于字符串“zyxl”和“1st Dam”之间的区域中的模式匹配的行,但不断开与“1st Dam”和“zyxl”之间匹配模式的任何行

“查找内容”中的以下代码将找到我想要断线的区域:

(?s)^\t*zyxl(.|\r\n)*?1st Dam

此代码将找到我不想破坏代码的区域:

(?s)^\t*1st Dam (.|\r\n)*?zyxl

有没有办法,可以通过组合这些方法,或者以其他方式重新排列文本,以便……  

zyxl
QUEENB BLUE CHIP  
Super Bowl 3,1:56.2 Armbro Goal 3,1:54.3 Grassbed 2,1:59.1  
1st Dam 
RICHESSE OBLIGE Varenne. 13 wins, 2 thru 5. This is her first foal. 
zyxl

VENERATE 
Super Bowl 3,1:56.2 Armbro Goal 3,1:54.3 Grassbed 2,1:59.1  
1st Dam
RICHESSE OBLIGE 13 wins, 2 thru 5. This is her first foal. 
Zyxl

…变成

zyxl
QUEENB BLUE CHIP  
Super Bowl 3,1:56.2
Armbro Goal 3,1:54.3
Grassbed 2,1:59.1  
1st Dam 
RICHESSE OBLIGE Varenne. 13 wins, 2 thru 5. This is her first foal. 
zyxl

VENERATE 
Super Bowl 3,1:56.2
Armbro Goal 3,1:54.3
Grassbed 2,1:59.1  
1st Dam 
RICHESSE OBLIGE 13 wins, 2 thru 5. This is her first foal. 
zyxl

提前感谢您的时间和帮助。

答案1

假设该行前面有“zyxl” VENERATE


  • Ctrl+H
  • 找什么:(?:zyxl|\G)(?:(?!1st Dam).)*?\d\K\h+(?=[A-Z])
  • 替换为:\n\r\n适用于 Windows EOL
  • 查看 相符
  • 查看 环绕
  • 查看 正则表达式
  • 查看 . matches newline
  • Replace all

解释:

(?:zyxl|\G)             # non capture group, matches zyxl or restart from last match position
(?:(?!1st Dam).)*?      # Tempered Greedy Token, make sure we don't encountered "1st Dam"
\d                      # a digit
\K                      # forget all we have seen until this position
\h+                     # 1 or more horizontal spaces
(?=[A-Z])               # positive lookahead, make sure we have an uppercase after

截图(之前):

在此处输入图片描述

截图(之后):

在此处输入图片描述

相关内容