"李江1" <[email protected]>,"李江2" <[email protected]>,"李江3" <[email protected]>,"李江4" <[email protected]>,"李江1" <[email protected]>,"李江2" <[email protected]>,"李江3" <[email protected]>,"李江4" <[email protected]>,"李江1" <[email protected]>,"李江2" <[email protected]>,"李江3" <[email protected]>,"李江4" <[email protected]>
在文本框输入这么多的内容,,,怎么用javascript,,,,和java这两种语言,,,,,的正则表达式进行验证
在文本框输入这么多的内容,,,怎么用javascript,,,,和java这两种语言,,,,,的正则表达式进行验证
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.*;//正则表达式获取网页上的邮箱地址
public class MyRegex {
public static void main(String[] args) {
try {
//读取网页文件,里面有N个邮箱地址
String content = read("e:/1.htm");//read()方法在下面
//匹配邮箱的正则表达式
String regex="\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
Matcher m=Pattern.compile(regex).matcher(content);
while(m.find()){
//输出邮箱地址
System.out.println(m.group());
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 读取文本内容
* @param fileName 文本名称,包括路径
* @return 返回文本内容
*/
public static String read(String fileName) throws IOException{
BufferedReader br=new BufferedReader(new FileReader(fileName));
StringBuilder sb=new StringBuilder();
String s;
while((s=br.readLine())!=null)
{
sb.append(s);
sb.append("\r\n");
}
br.close();
return sb.toString();
}
}
Pattern p1=Pattern.compile("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");Matcher m1=p1.matcher("\"李江1\" <[email protected]>,\"李江2\" <[email protected]>,\"李江3\" <[email protected]>");
System.out.println(m1.matches());//为什么是false这是合法的呀,,,,
还是没明白我说的什么意思呀,哈哈,,,真有点想不明白,,,,我这个问题怎么解决,,,哈哈,,,
有人会吗,哈哈,,,来给说一下,,,,我在这里说声谢谢了,
{
public static void main(String[] args)
{
String content = "\"李江1\" <[email protected]>,\"李江2\" <[email protected]>," +
"\"李江3\" <[email protected]>,\"李江4\" <[email protected]>," +
"\"李江1\" <[email protected]>,\"李江2\" <[email protected]>," +
"\"李江3\" <[email protected]>,\"李江4\" <[email protected]>," +
"\"李江1\" <[email protected]>,\"李江2\" <[email protected]>," +
"\"李江3\" <[email protected]>,\"李江4\" <[email protected]> ";
// 匹配邮箱的正则表达式
String regex = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
Matcher m = Pattern.compile(regex).matcher(content);
while (m.find())
{
// 输出邮箱地址
System.out.println(m.group());
}
}
}
function isEmail(str){
var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
return reg.test(str);
}
[email protected]
[email protected]
[email protected]
1、收信人的名字不能为空,也不能为空格;
2、如果出现了违反1的情况,则其后续的匹配中会在符合条件的字符串前多一个逗号,这是表达式匹配所产生的,处理时可以去掉。只是简单测试了一下,没有仔细测试。
String reg1 = "(\"[^\"]+\" *(<([\\w]+)(.[\\w]+)*@([\\w-]+\\.){1,5}([A-Za-z]){2,4}>),)*(\"[^\"]+\" *(<([\\w]+)(.[\\w]+)*@([\\w-]+\\.){1,5}([A-Za-z]){2,4}>))";
String text = "\"姓名\"<[email protected]>,\"姓名\"<[email protected]>,\"姓名\"<[email protected]>,\"姓名\"<[email protected]>";
String text1 = "\"姓名\"<[email protected]>,";
String text2 = "\"姓名\"<aaaayahoo.cn>,\"姓名\"<[email protected]>";
String text3 = "\"<aaaayahoo.cn>,\"姓名\"<[email protected]>";
Pattern pp = Pattern.compile(reg1);
System.out.println(pp.matcher(text).matches());
System.out.println(pp.matcher(text1).matches());
System.out.println(pp.matcher(text2).matches());
System.out.println(pp.matcher(text3).matches());