我希望从频繁的输出文档中搜索/删除一些复杂的文本。 (请参阅问题的底部以获取源文本)
使用正则表达式,我希望:
留下这样的行:1234TH-ST-TA5000-1#sh in sh 1/7/12 re
删除此:several lines of whitespace
在此行之前停止:-------------------------------
我当前的正则表达式使用环视开始匹配第一行后,但由于某种原因,它包括匹配中的第一行,只找到第一个实例(应该匹配/删除六个或七个)。
当前的RegEx:(?:(\r|\n|\r\n).+-TA5000-\d\#sh in sh \d+\/\d+\/\d+ re\b)\s+
来源文字:
1234TH-ST-TA5000-1#sh in sh 1/7/12 re
--------------------------------------------------------------------------------
SHDSL 1/7/12
Description 690686
Admin Status In Service
Oper Status Up
Channel Rate (kbps) 2624
ES 0
SES 0
UAS 0
CVC 0
LOSWS 0
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) 18,18,18 (Cur, Min, Max)
SNR Margin Current Train (dB) 18,6,18 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,17,17 (Cur, Min, Max)
Loop Attenuation (dB) 15,15,15 (Cur, Min, Max)
Upstream PBO (dB) 0
Downstream PBO (dB) 0
Annex A/B/EFM
Line Probe Disabled
(OUTPUT TRUNCATED)--------------------------------------------------------------
Exit - 'Ctrl-C', Clear - 'c', Freeze - 'f', Resume - 'r'
SHDSL 1/7/12
Description 690686
Admin Status In Service
Oper Status Up
Channel Rate (kbps) 2624
ES 0
SES 0
UAS 0
CVC 0
LOSWS 0
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) 18,18,18 (Cur, Min, Max)
SNR Margin Current Train (dB) 18,6,18 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,17,17 (Cur, Min, Max)
Loop Attenuation (dB) 15,15,15 (Cur, Min, Max)
Upstream PBO (dB) 0
Downstream PBO (dB) 0
Annex A/B/EFM
Line Probe Disabled
Line Rate (N x DS0s) 41,41,41 (Cur, Min, Max)
Constellation Crossover (DS0s) 60
Constellation (bits/baud) 3
1234TH-ST-TA5000-1#sh in sh 1/2/24 re
--------------------------------------------------------------------------------
SHDSL 1/2/24
Description 689932
Admin Status In Service
Oper Status Up
Channel Rate (kbps) 832
ES 0
SES 0
UAS 0
CVC 0
LOSWS 0
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) 29,29,29 (Cur, Min, Max)
SNR Margin Current Train (dB) 29,4,70 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,2,4 (Cur, Min, Max)
Loop Attenuation (dB) 6,6,6 (Cur, Min, Max)
Upstream PBO (dB) 3
Downstream PBO (dB) 4
Annex A/B/EFM
Line Probe Disabled
(OUTPUT TRUNCATED)--------------------------------------------------------------
Exit - 'Ctrl-C', Clear - 'c', Freeze - 'f', Resume - 'r'
SHDSL 1/2/24
Description 689932
Admin Status In Service
Oper Status Up
Channel Rate (kbps) 832
ES 0
SES 0
UAS 0
CVC 0
LOSWS 0
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) 29,29,29 (Cur, Min, Max)
SNR Margin Current Train (dB) 29,4,70 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,2,4 (Cur, Min, Max)
Loop Attenuation (dB) 6,6,6 (Cur, Min, Max)
Upstream PBO (dB) 3
Downstream PBO (dB) 4
Annex A/B/EFM
Line Probe Disabled
Line Rate (N x DS0s) 13,13,13 (Cur, Min, Max)
Constellation Crossover (DS0s) 60
Constellation (bits/baud) 3
1234TH-ST-TA5000-1#sh in sh 1/7/1 re
--------------------------------------------------------------------------------
SHDSL 1/7/1
Description
Admin Status Out of Service - Unassigned
Oper Status Down
Channel Rate (kbps) 0
ES 0
SES 0
UAS 0
CVC 0
LOSWS 0
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) -2,-2,-2 (Cur, Min, Max)
SNR Margin Current Train (dB) 0,0,0 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,8,12 (Cur, Min, Max)
Loop Attenuation (dB) 27,27,27 (Cur, Min, Max)
Upstream PBO (dB) 0
Downstream PBO (dB) 0
Annex A/B/EFM
Line Probe Worstcase
(OUTPUT TRUNCATED)--------------------------------------------------------------
Exit - 'Ctrl-C', Clear - 'c', Freeze - 'f', Resume - 'r'
SHDSL 1/7/1
Description
Admin Status Out of Service - Unassigned
Oper Status Down
Channel Rate (kbps) 0
ES 0
SES 0
UAS 0
CVC 0
LOSWS 0
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) -2,-2,-2 (Cur, Min, Max)
SNR Margin Current Train (dB) 0,0,0 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,8,12 (Cur, Min, Max)
Loop Attenuation (dB) 27,27,27 (Cur, Min, Max)
Upstream PBO (dB) 0
Downstream PBO (dB) 0
Annex A/B/EFM
Line Probe Worstcase
Worst Case Margin 3
Line Rate (N x DS0s) 0,3,89 (Cur, Min, Max)
Constellation Crossover (DS0s) 60
1234TH-ST-TA5000-1#sh in sh 1/7/31 re
--------------------------------------------------------------------------------
SHDSL 1/7/31
Description 690689
Admin Status In Service
Oper Status Up
Channel Rate (kbps) 1472
ES 0
SES 0
UAS 0
CVC 0
LOSWS 0
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) 26,26,26 (Cur, Min, Max)
SNR Margin Current Train (dB) 26,23,27 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,27,27 (Cur, Min, Max)
Loop Attenuation (dB) 7,7,7 (Cur, Min, Max)
Upstream PBO (dB) 3
Downstream PBO (dB) 4
Annex A/B/EFM
Line Probe Disabled
(OUTPUT TRUNCATED)--------------------------------------------------------------
Exit - 'Ctrl-C', Clear - 'c', Freeze - 'f', Resume - 'r'
SHDSL 1/7/31
Description 690689
Admin Status In Service
Oper Status Up
Channel Rate (kbps) 1472
ES 0
SES 0
UAS 0
CVC 0
LOSWS 0
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) 26,26,26 (Cur, Min, Max)
SNR Margin Current Train (dB) 26,23,27 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,27,27 (Cur, Min, Max)
Loop Attenuation (dB) 7,7,7 (Cur, Min, Max)
Upstream PBO (dB) 3
Downstream PBO (dB) 4
Annex A/B/EFM
Line Probe Disabled
Line Rate (N x DS0s) 23,23,23 (Cur, Min, Max)
Constellation Crossover (DS0s) 60
Constellation (bits/baud) 3
1234TH-ST-TA5000-1#sh in sh 1/7/32 re
--------------------------------------------------------------------------------
SHDSL 1/7/32
Description 690690
Admin Status In Service
Oper Status Down
Channel Rate (kbps) 0
ES 0
SES 0
UAS 1
CVC 0
LOSWS 1
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) -3,-3,-3 (Cur, Min, Max)
SNR Margin Current Train (dB) 0,0,0 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,0,8 (Cur, Min, Max)
Loop Attenuation (dB) 46,46,46 (Cur, Min, Max)
Upstream PBO (dB) 0
Downstream PBO (dB) 0
Annex A/B/EFM
Line Probe Disabled
(OUTPUT TRUNCATED)--------------------------------------------------------------
Exit - 'Ctrl-C', Clear - 'c', Freeze - 'f', Resume - 'r'
SHDSL 1/7/32
Description 690690
Admin Status In Service
Oper Status Down
Channel Rate (kbps) 0
ES 0
SES 0
UAS 2
CVC 0
LOSWS 2
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) -3,-3,-3 (Cur, Min, Max)
SNR Margin Current Train (dB) 0,0,0 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,0,8 (Cur, Min, Max)
Loop Attenuation (dB) 46,46,46 (Cur, Min, Max)
Upstream PBO (dB) 0
Downstream PBO (dB) 0
Annex A/B/EFM
Line Probe Disabled
Line Rate (N x DS0s) 0,20,20 (Cur, Min, Max)
Constellation Crossover (DS0s) 60
Constellation (bits/baud) N/A
1234TH-ST-TA5000-1#sh in sh 1/7/10 re
--------------------------------------------------------------------------------
SHDSL 1/7/10
Description 690685
Admin Status In Service
Oper Status Down
Channel Rate (kbps) 0
ES 57020
SES 92
UAS 132288
CVC 138706
LOSWS 131657
Retrains 728
Handshake Failures 0
SNR Margin Absolute (dB) -2,-8,20 (Cur, Min, Max)
SNR Margin Current Train (dB) 0,0,0 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,6,10 (Cur, Min, Max)
Loop Attenuation (dB) 20,8,37 (Cur, Min, Max)
Upstream PBO (dB) 0
Downstream PBO (dB) 1
Annex A/B/EFM
Line Probe Disabled
(OUTPUT TRUNCATED)--------------------------------------------------------------
Exit - 'Ctrl-C', Clear - 'c', Freeze - 'f', Resume - 'r'
SHDSL 1/7/10
Description 690685
Admin Status In Service
Oper Status Down
Channel Rate (kbps) 0
ES 0
SES 0
UAS 0
CVC 0
LOSWS 0
Retrains 0
Handshake Failures 0
SNR Margin Absolute (dB) -2,-2,-2 (Cur, Min, Max)
SNR Margin Current Train (dB) 0,0,0 (Cur, Min, Max)
SNR Margin Previous Train (dB) na,6,10 (Cur, Min, Max)
Loop Attenuation (dB) 20,20,20 (Cur, Min, Max)
Upstream PBO (dB) 0
Downstream PBO (dB) 1
Annex A/B/EFM
Line Probe Disabled
Line Rate (N x DS0s) 0,19,19 (Cur, Min, Max)
Constellation Crossover (DS0s) 60
Constellation (bits/baud) N/A
1234TH-ST-TA5000-1#

答案 0 :(得分:2)
您可以使用
(^.+-TA5000-\d#sh in sh \d+/\d+/\d+ re$)\s+
并替换为$1\n
。
请参阅regex demo。
请注意,Notepad ++ regexp不使用正则表达式分隔符,不需要转义正斜杠。
此外,NPP正则表达式默认使用多行选项,^
匹配行的开头,因此,我在测试时在regex101.com启用了m
选项。我还在那里启用了g
选项以查找多个匹配项(模拟全部替换)。
模式详情:
(^.+-TA5000-\d#sh in sh \d+/\d+/\d+ re$)
- 第1组(从替换模式引用$1
反向引用):
^
- 开始行.+
- 换行符号以外的任何1个字符-TA5000-
- 文字子字符串\d
- 数字#sh in sh
- 文字子字符串\d+/\d+/\d+
- 1位数,/
,1位数,/
,1位数 re
- 字面意思"重新"子$
- 行尾\s+
- 任何空白符号中的一个或多个(这些将被删除)。