Home Ask Login Register

Developers Planet

Your answer is one click away!

user3269606 February 2016

how to not match a pattern in xml

Log collector takes path to collect the log files. How to omit the "undo" files present in path4 directory.
Collect logs from path below but omit undo files from path4

    <log path="/path1/path2/path3/^[undo]*"/>  



Daniel Martin February 2016

Assuming from the tags that this log collector takes a perl regular expression or something like it, then it'd be:

    <log path="/path1/path2/path3/(?!undo)[^/]*"/>  

(Depending on whether the log collector needs the regular expression to match the whole file name, the [^/]* at the end may not be necessary)

Unfortunately, the name "log collector" is a bit generic, so I don't actually know what software you mean, so I don't know if it in fact does take a perl regular expression; it would be helpful to give a reference to the actual software your using.

Okay, here's what that that regular expression should match, using this perl test program:

my $re = qr{/path1/path2/path3/(?!undo)[^/]*};

for (<>) {
  if ($_ =~ $re) {
    print "$_ matches\n"
  } else {
    print "$_ DOES NOT MATCH\n"

That shows us:

/path1/path2/path3/foo.txt matches
/path1/path2/path3/bar.log matches
/path1/path2/path3/undo_5.txt DOES NOT MATCH
/path1/path2/path3/ matches

This is why I really wanted a pointer to the software. Because you say that the revised regex does not work, that "undo" files are still getting pulled in, and that tells me that the log software does not match the full filename to the regular expression, but only the path (directory) name. We can see from the evidence above that the regular expression does not match files with names beginning with "undo".

And since you want some files in the directory to be matched and some not, you should hope that your software has something like a separate file= attribute that accepts a regular expression for the file names.

Post Status

Asked in February 2016
Viewed 1,739 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life