我手边没有 PERL 解释器,但这似乎在 Java 中有效:
^.*format=(?!(?:image/)?(?:kml|kmz|png|jpeg|tiff)).*$
这是测试它的代码段:
private static final Pattern REGEX =
Pattern.compile("^.*format=(?!(?:image/)?(?:kml|kmz|png|jpeg|tiff)).*$");
public static void main(String[] args) {
for (String format : Arrays.asList("foo&bar&format=image/png",
"foo&bar&format=kml&baz", "foo&bar&format=image/svg",
"foo&bar&format=application/pdf&baz")) {
System.out.printf("%s %s%n", format,
REGEX.matcher(format).matches() ? "matches" : "does not match");
}
}
印刷:
foo&bar&format=image/png does not match
foo&bar&format=kml&baz does not match
foo&bar&format=image/svg matches
foo&bar&format=application/pdf&baz matches