Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi Stephan,

thanks for adjusting the regex. false positives like if (foo) delete bar wouldn't occur within my regex (the inner one). But this is some kind of hidden (the $1). I did this some kind of obfuscated, because I didn't remembered \1 for lookaheads ;)

I you want to, run it :)

On 09/19/2011 10:52 PM, Stephan Bergmann wrote:
By the way, using the below regexps (best run in a C locale) should find
even more instances, and should avoid false positives of the form "if
(foo) delete bar;" or (unlikely) "#if (foo) \n delete foo;":

foreach (@ARGV) {
my $file = $_;
open(FH, "<$file");
my $data = "";
while (<FH>) { $data .= $_; }
close(FH);
while ($data =~ /((?<!#)\s*\bif\s*\(\s*(\w+)\s*\)\s*delete\s+\2\s*;)/g) {
print "found <$1>\n";
}
while ($data =~
/((?<!#)\s*\bif\s*\(\s*(\w+)\s*\)\s*{\s*delete\s+\2\s*;\s*})/g) {
print "found <$1>\n";
}
}

(The outer parentheses are only there for print "found <$1>\n" to work
-- no idea how Perl makes available the complete match without that
hack... The leading "(?<!#)\s*" should really read "(?<!#\s*)", but then
Perl complains that "Variable length lookbehind [is] not implemented.")

Thomas

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.