はnegative lookbehind(java example)です。
このパターンは、 ".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.");
}
}
}
ので:
% javac NegativeLookbehindExample.java && java NegativeLookbehindExample
"example.dot" is a match.
"example.xhtml" is NOT a match.
"example.xhtml.thingy" is a match.
残念ながら、これは機能しません(確認のためにテストされています)。おそらくネガティブなルックアヘッドアサーションは先読みするために何か他のものを必要とするからです! –
私が上記のコメントを投稿するまでに、その答えは否定的なルック・バック・アサーションに編集されました。しかし、これはどちらもうまくいかない。 –
もちろん、サンプルコードを試してみてください。 – rampion