java - Regex that excludes filename with certains extensions -


i trying find regex allows filename not have certains extensions. example:

  • test.pdf => ok
  • test.exe => ko
  • test.tmp => ko
  • test.exe => ko
  • test.pdf => ok

i can't use ends because have put entire regex in .properties file.

i tried ^.*\.(^exe|^tmp)$ not work @ all.

edit: not duplicate of regex file extension because need ignore extensions. not purpose of other question.

hope might help!

public class stackoverflowquestion45321328 {      public static void main(string[] args) {          list<string> data = new arraylist();         data.add("test.pdf");         data.add("test.exe");         data.add("test.tmp");         data.add("test.exe");         data.add("test.pdf");          string regex = "^.*(?<!exe|tmp)$";         pattern pattern = pattern.compile(regex, pattern.case_insensitive);          (string filename : data) {             matcher matcher = pattern.matcher(filename);             boolean ismatchingpattern = matcher.matches();             system.out.println(filename + " : " + ismatchingpattern);         }     } } 

output:

test.pdf : true test.exe : false test.tmp : false test.exe : false test.pdf : true 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -