I’d like a regex to match everything but a few specific options within a broader expression.
The following example will match test_foo.pl or test_bar.pl or test_baz.pl:
/test_(foo|bar|baz)\.pl/
But I’d like just the opposite:
match test_.*\.pl except for where .* = (foo|bar|baz)
I’m kind of limited in my options for this because this is not directly into a perl program, but an argument to cloc, a program that counts lines of code (that happens to be written in perl). So I’m looking for an answer that can be done in one regex, not multiple chained together.
You should be able to accomplish this by using a negative lookahead:
This will fail if
foo,bar, orbazimmediately followstest_.Note that this could still match something like
test_notfoo.pl, and would fail ontest_fool.pl, if you do not want this behavior please clarify by adding some examples of what exactly should and should not match.If you want to accept something like
test_fool.plortest_bart.pl, then you could change it to the following: