最近写了个Java正则表达式来验证RFC 5322规范的邮件地址,这个邮件地址比较复杂,对于这样一个地址:userName@domainName,它满足以下条件:
对于userName
1、允许使用以下所有字符作为用户名:
[A-Z], [a-z], [0-9], [.], [-], [_], [@], [!], [#], [$], [%], [&], [‘], [*], [+], [/], [=], [?], [^], [`], [{], [|], [}], [~]
2、允许使用所有的ASCII字符,包括控制字符,前提条件是这些字符是被[\]所转义的或者被一对[“]所包括起来,比如下边的格式:
” [ ♥”或者\]都是合法的用户名
3、[.]不能出现在用户名的开头或者结尾,也不能连续出现两个以上的[.]
对于domainName
1、只能使用[A-Z],[a-z],[0-9],[-]
2、如果使用了[-],那么该字符不能出现在域名的开头或结尾
3、顶级域名不能全是数字
4、至少要有二级域名
Java正则表达式
由于是用来验证邮件地址的,使用的是matches()这个完全匹配的方法,并且使用非捕获组来提高性能。
写了两个正则表达式,一个是用来验证单个邮件地址的(比如xxx@xx.xx);一个是用来验证多个邮件地址的,即多个邮件地址之间用空白符或者英文的逗号或分号分割开来(比如xxx@xx.xx; xx@xxx.xxx)。
/** Regex format for multiple EmailValidator */
public static final String MULTIPLE_EMAIL_REGEX_FORMAT = "(?:(?:%1$s)(?:(?:\\s*,\\s*)|(?:\\s*;\\s*)|\\s*$))*";
/** Regex for single EmailValidator */
public static final String SINGLE_EMAIL_REGEX = "(?:(?:[A-Za-z0-9\\-_@!#$%&'*+/=?^`{|}~]|(?:\\\\[\\x00-\\xFF]?)|(?:\"[\\x00-\\xFF]*\"))+(?:\\.(?:(?:[A-Za-z0-9\\-_@!#$%&'*+/=?^`{|}~])|(?:\\\\[\\x00-\\xFF]?)|(?:\"[\\x00-\\xFF]*\"))+)*)@(?:(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\.)+(?:(?:[A-Za-z0-9]*[A-Za-z][A-Za-z0-9]*)(?:[A-Za-z0-9-]*[A-Za-z0-9])?))";
public static final Pattern SINGLE_EMAIL_REGEX_PATTERN = Pattern.compile(SINGLE_EMAIL_REGEX);
/** Regex for multiple EmailValidator */
public static final String MULTIPLE_EMAIL_REGEX = String.format(MULTIPLE_EMAIL_REGEX_FORMAT, SINGLE_EMAIL_REGEX);
public static final Pattern MULTIPLE_EMAIL_REGEX_PATTERN = Pattern.compile(MULTIPLE_EMAIL_REGEX);
上边验证单个邮件地址的正则表达式太长了,这里分一下行:
public static final String SINGLE_EMAIL_REGEX = "(?:(?:[A-Za-z0-9\\-_@!#$%&'*+/=?
^`{|}~]|(?:\\\\[\\x00-\\xFF]?)|(?:\"[\\x00-\\xFF]*\"))+(?:\\.(?:(?:[A-Za-z0-9\\-
_@!#$%&'*+/=?^`{|}~])|(?:\\\\[\\x00-\\xFF]?)|(?:\"[\\x00-\\xFF]*\"))+)*)
@(?:(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\.)+
(?:(?:[A-Za-z0-9]*[A-Za-z][A-Za-z0-9]*)(?:[A-Za-z0-9-]*[A-Za-z0-9])?))";
最后附上一些测试用的邮件地址
// =========TRUE EMAIL==========
final String email = "Abc\\@def@example.com"; //true
// final String email = "Fred\\ Bloggs@example.com"; //true
// final String email = "Joe.\\\\Bloggs@example.com"; //true
// final String email = "\"Abc@def\"@example.com"; //true
// final String email = "\"Fred Bloggs\"@example.com"; //true
// final String email = "user+mailbox@example.com"; //true
// final String email = "customer/department=shipping@example.com"; //true
// final String email = "$A12345@example.com"; //true
// final String email = "!def!xyz%abc@example.com"; //true
// final String email = "_somename@example.com"; //true
// final String email = "Natasha.O'neill@thewarehouse.com"; //true
// final String email = "ab.c@exam-ple.c--om"; // true
// final String email = "------ab.c@example.12.com"; // true
// final String email = "------ab.c@example.12.com "; // true
// ==========FALSE EMAIL==========
// final String email = "abc[@example.com"; //false
// final String email = ".abc@example.com"; //false
// final String email = "ab..c@example.com"; // false
// final String email = "ab.c@example.com."; // false
// final String email = "ab.c@example.com-"; // false
// final String email = "------ab.c.@example.com"; // false
// final String email = "------ab.c@-example-.com"; // false
// final String email = "------ab.c@com"; // false
// final String email = "------ab.c@example.12"; // false
python将图片转为矩阵 python怎么把图片转换为矩阵
from PIL import Image #矩阵转图片使用
import matplotlib.image #图片转矩阵使用
#图片转为矩阵 imead
img=matplotlib.image.imread("C:\\Users\\Administrator\\Desktop\\2007009.500m_16_days_NDVI.tif")
print(img.shape)
--js代码:
-------------------------------------------------------------------------------------------
function preview(){
bdhtml=window.document.body.innerHTML; //定义打印内容
1、枚举类如下 package com.irobotzz.docs.bms.constants;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.common.auth.constants.IBaseEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
python 读取一组数据结构 python读取数组元素
1 读取数据先看下面一段代码array = np.arange(0,20)
array = array.reshape(4,5)
print(array)
print(array[1,2])
print(array[1][2])
print(array[2, :])
col = [1,3]
array[:,col] = array[:,col]+1
print(array[:,col])代码的输出