public final class RegexConstants extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DIGITAL_REGEX |
static String |
DOMAIN_REGEX
域名的正则表达式, 针对域名的解析, 例如: www.example.com , www.example.com.cn, www.example.top aaa.bbb.example.cc,
127.0.0.1
|
static String |
MOBILE_PATTERN
手机号正则表达式
|
static String |
RFC_6819_CHECK_REGEX
RFC 6819 安全检查(https://oauth.net/advisories/2014-1-covert-redirect/)时, 使用的正则表达式
|
static int |
TOP_DOMAIN_INDEX
DOMAIN_REGEX 的正则表达式中一级域名的组的索引, 对于 ip 形式的不适用. |
static String |
URL_SCHEME_REGEX
url scheme regex
|
public static final String RFC_6819_CHECK_REGEX
public static final String DOMAIN_REGEX
public static final int TOP_DOMAIN_INDEX
DOMAIN_REGEX 的正则表达式中一级域名的组的索引, 对于 ip 形式的不适用. 例如:
String domain = "www.xxx.com.cn";
Pattern pattern = Pattern.compile(DOMAIN_REGEX);
Matcher matcher = pattern.matcher(domain);
if (matcher.find()) {
String topDomain = matcher.group(TOP_DOMAIN_INDEX);
}
// 输出:
domain: www.example.com -> topDomain: example.com
domain: www.example.com.cn -> topDomain: example.com.cn
// 注意: 对于 ip 形式的不适用
domain: 127.0.0.1 -> topDomain: 0.1
Copyright © 2021. All rights reserved.