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

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

/path1/path2/path3/path4/undo1.txt
/path1/path2/path3/path4/undo2.txt

Answers


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:

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

(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 (<>) {
  chomp;
  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

Search




Leave an answer