Patterns.java

 1package de.gultsch.common;
 2
 3import java.util.regex.Pattern;
 4
 5public class Patterns {
 6
 7    public static final Pattern URI_GENERIC =
 8            Pattern.compile(
 9                    "(?<=^|\\p{Z}|\\s|\\p{P}|<)(tel|xmpp|http|https|geo|mailto|web\\+ap|gemini):[\\p{L}\\p{M}\\p{N}\\-._~:/?#\\[\\]@!$&'*+,;=%]+(\\([\\p{L}\\p{M}\\p{N}\\-._~:/?#\\[\\]@!$&'*+,;=%]+\\))*[\\p{L}\\p{M}\\p{N}\\-._~:/?#\\[\\]@!$&'*+,;=%]*");
10
11    public static final Pattern URI_TEL =
12            Pattern.compile("^tel:\\+?(\\d{1,4}[-./()\\s]?)*\\d{1,4}(;.*)?$");
13
14    public static final Pattern URI_HTTP = Pattern.compile("https?://\\S+");
15
16    public static final Pattern URI_WEB_AP = Pattern.compile("web\\+ap://\\S+");
17
18    public static Pattern URI_GEO =
19            Pattern.compile(
20                    "geo:(-?\\d+(?:\\.\\d+)?),(-?\\d+(?:\\.\\d+)?)(?:,-?\\d+(?:\\.\\d+)?)?(?:;crs=[\\w-]+)?(?:;u=\\d+(?:\\.\\d+)?)?(?:;[\\w-]+=(?:[\\w-_.!~*'()]|%[\\da-f][\\da-f])+)*(\\?z=\\d+)?",
21                    Pattern.CASE_INSENSITIVE);
22
23    public static final Pattern IPV4 =
24            Pattern.compile(
25                    "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z");
26    public static final Pattern IPV6 =
27            Pattern.compile("\\A(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\\z");
28    public static final Pattern IPV6_HEX4_DECOMPRESSED =
29            Pattern.compile(
30                    "\\A((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)"
31                        + " ::((?:[0-9A-Fa-f]{1,4}:)*)(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z");
32    public static final Pattern IPV6_6HEX4DEC =
33            Pattern.compile(
34                    "\\A((?:[0-9A-Fa-f]{1,4}:){6,6})(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z");
35    public static final Pattern IPV6_HEX_COMPRESSED =
36            Pattern.compile(
37                    "\\A((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)\\z");
38
39    private Patterns() {
40        throw new AssertionError("Do not instantiate me");
41    }
42}