markbernard markbernard - 1 year ago 60
Java Question

Regular expression to return results that do not match selection

I work on a product that provides a Java API to extend it.

The API provides a function which
takes a Perl regular expression and
returns a list of matching files.

I want to filter the list to remove all files that end in

; basically the opposite of

I have been searching but I haven't been able to get anything to work yet.

I tried

I don't know if I am on the right track or not.


I know the regex systems are similar, but I can't get a Java regex working either.

Answer Source

You may use


See the regex demo


  • ^ - start of a string
  • (?!.*\.(x[ms]l|cfg)$) - a negative lookahead that fails the match if any 0+ chars other than line break chars (.*) are followed with xml, xsl or cfg ((x[ms]l|cfg)) at the end of the string ($)
  • .+ - any 1 or more chars other than linebreak chars. Might be omitted if the entire string match is not required (in some tools it is required though).
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download