我有一个来自配置文件的片段,我需要能够匹配指定的字符串引用内容,但只有当它们没有被注释掉时,这是我当前的正则表达式:
(?<!=#)test\.this\.regex\s+\"(.*?)\"
我觉得这应该工作?我是这样读的:
(?<!=#)
向后看以确保它前面没有#
test\.this\.regex\s+\"(.*?)\"
火柴test.this.regex "sup1"
这是配置片段
test.this.regex "sup1" hi |sup1| # test.this.regex "sup3" hi |sup3|
# test.this.regex "sup2" do |sup2|
test.this.regex "sup2" do |sup2|
但我的正则表达式匹配所有 4 次:
Match 1
1. sup1
Match 2
1. sup3
Match 3
1. sup2
Match 4
1. sup2