What you need is a negative lookbehind ( java example ).
String regex = ".*(?<!\\.xhtml)$"; Pattern pattern = Pattern.compile(regex);
This template matches any that does not end with ".xhtml".
import java.util.regex.Matcher; import java.util.regex.Pattern; public class NegativeLookbehindExample { public static void main(String args[]) throws Exception { String regex = ".*(?<!\\.xhtml)$"; Pattern pattern = Pattern.compile(regex); String[] examples = { "example.dot", "example.xhtml", "example.xhtml.thingy" }; for (String ex : examples) { Matcher matcher = pattern.matcher(ex); System.out.println("\""+ ex + "\" is " + (matcher.find() ? "" : "NOT ") + "a match."); } } }
So:
% javac NegativeLookbehindExample.java && java NegativeLookbehindExample "example.dot" is a match. "example.xhtml" is NOT a match. "example.xhtml.thingy" is a match.
rampion
source share