I have a fragment of a configuration file that should match the specified contents of a line string, but only when they are not commented out, here is my current regular expression:
(?<!=#)test\.this\.regex\s+\"(.*?)\"
I feel this should work? I read it as follows:
(?<!=#) lookbehind to make sure it is not preceded #
test\.this\.regex\s+\"(.*?)\" corresponds to test.this.regex "sup1"
Here is a fragment of the configuration
test.this.regex "sup1" hi |sup1| # test.this.regex "sup3" hi |sup3|
# test.this.regex "sup2" do |sup2|
test.this.regex "sup2" do |sup2|
But my regex matches all 4 times:
Match 1
1. sup1
Match 2
1. sup3
Match 3
1. sup2
Match 4
1. sup2
source
share