我之前的问题被标记为this question的副本,但标记为重复的问题提倡使用非贪婪的开关来解决问题。
这个问题断言非贪婪的开关已经被使用,并要求回答非贪婪开关为什么没有按预期工作,如this regex101 fiddle
所示。说明:
我正在尝试在我的正则表达式友好的Notepad ++编辑器中搜索/替换一些谨慎的输出块。
这是我现在的正则表达式:
^\s*Rate Control[\s\S]*(XCV Link Removal\s+: enable\s+\n)?
匹配正确开始,但由于某种原因,它不会停留在第一个端点,但会选择文档之间的所有文本到文档中类似代码块的最后一个实例的末尾。
我尝试将非贪婪的开关(?)添加到模式的末尾:(s+\n?)
并将"搜索添加到" parens (XCV Link Removal\s+: enable\s+\n)?
中的文字,但我没有在这里找到最佳位置。
这是我正在搜索的文本(底部是一个regex101小提琴,还包含要搜索的输出文本):
interface efm-group 1/2/13 is IS and up
Alias : ABC - SOME DEVICE - 18224001
Active Slot : 2
Provisioned Links : 2/14, 2/24, 7/10, 7/12, 7/25, 7/31, 7/32
Active Links : 2/14, 2/24, 7/12, 7/31
Inhibited Links : None
Rate Control : Off
Min Num Active Links : 1
Loopback : disable
XCV Threshold : 1e-7
XCV Link Removal : enable
Upstream Downstream
Rate kbps : 5632 5632
Receive Transmit
Frames : 4232824098 4694020515
Bytes : 475438534984 1373797640289
Discarded Frames : na 38100707
Discarded Bytes : na 44759197139
Bad Fragments : 0 na
Lost Fragments : 761 na
Lost Start Fragments : 408 na
Lost End Fragments : 378 na
Lots of more silly stuffs
Lots of more silly stuffs Lots of more silly stuffs Lots of more silly stuffs Lots of more silly stuffs Lots of more silly stuffs Lots of more silly stuffs
Lots of more silly stuffs Lots of more silly stuffs Lots of more silly stuffs Lots of more silly stuffs Lots of more silly stuffs
Lots of more silly stuffs Lots of more silly stuffs Lots of more silly stuffs Lots of more silly stuffs v
56TH-ST-TA5000-1(config-shdsl 1/7/12)#do sh in efm-g 1/2/13
interface efm-group 1/2/13 is IS and up
Alias : DEF - NUTHER DEVICE - 16234003
Active Slot : 2
Provisioned Links : 2/14, 2/24, 7/10, 7/12, 7/25, 7/31, 7/32
Active Links : 2/14, 2/24, 7/12, 7/31
Inhibited Links : None
Rate Control : Off
Min Num Active Links : 1
Loopback : disable
XCV Threshold : 1e-7
XCV Link Removal : enable
Upstream Downstream
Rate kbps : 20928 20928
Receive Transmit
Frames : 4232889631 4694099150
Bytes : 475446102771 1373815313237
Discarded Frames : na 38107917
Discarded Bytes : na 44760275049
Bad Fragments : 0 na
Lost Fragments : 761 na
Lost Start Fragments : 408 na
Lost End Fragments : 378 na