跳到主要内容
CNode

【完美解决】求一段nodejs的邮箱正则表达式,用于匹配采集匹配的。

社区
Hheixiaoshan发布于 12 年前最后回复 12 年前
3128390

求一段nodejs的邮箱正则表达式,用于匹配采集匹配的。 多谢,我试了很多正则都无效。 代码如下:

	request = require('request');
var qHref= "http://www.douban.com/group/topic/10712106/";
//定义函数
	var getAHref = function(htmlstr){
//	    var reg = /<a.+?href=('|")?([^'"]+)('|")?(?:\s+|>)/gim;  //有效
	   var reg= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; //无值
	    var arr = [];
	    while(tem=reg.exec(htmlstr)){
	    	console.log("reg.exec(htmlstr)"+reg.exec(htmlstr));//好像没有进来执行
	    	console.log("tem[1]"+tem);//好像没有进来执行
	        arr.push(tem[2]);
	    }
	    return arr;
	}
exports. sp  = function(){
	request.get({url:qHref,headers:{'User-Agent': 'request'}}, function (error, response,data) {
		console.log('response.statusCode:'+response.statusCode);
	      if (!error && response.statusCode == 200) {
//	          console.dir(data);
	          var content = data;//获取到网页内容
	          var hrefs=getAHref(content);//获取链接
	           console.log(hrefs);  
	    }
	});
}
查看回复

回复 (3)

H
heixiaoshan#312 年前

修改以下2处完美解决: var reg= /[\w!#$%&'+/=?^_{|}~-]+(?:\.[\w!#$%&'*+/=?^_{|}~-]+)@(?:\w?.)+\w?/gim; arr.push(tem[0]);

H
heixiaoshan#212 年前
var	reg= /[^\@\s]{1,}\@(?:[^\s\.]{1,}\.){1,}(?:[a-z]{2,4}\.?){1,2}/gim ;   

正则换成这个有效。但是好像出来的东西有点不对头。 tem:
欢迎给我发邮件:[email protected] tem:class="">[email protected] tem:class="">[email protected] tem:class="">我留下我的邮箱你会给我回邮件吗?我要是的是长期电邮的那种,如果你不 是,不用给我回了![email protected] tem:class="">[email protected] tem:
[email protected] tem:class="">我每天打开电脑的第一件事情就是打开我的邮箱,查看有没有人给我联系, 六年了,我那些个熟悉的朋友,一个都没有给我发送过邮件,郁闷男+邮箱控+黑莓控等着您 的来信,[email protected]/[email protected] tem:想认识请电邮到:[email protected] tem:class="">[email protected] tem:class="">[email protected] tem:class="">我是来自成都的女生,我的邮件是[email protected] tem:class="">[email protected] tem:class="">[email protected] tem:class="">[email protected] tem:class="">[email protected] tem:class="">[email protected] tem:class="">[email protected] tem:[email protected] tem:class="">[email protected]

H
heixiaoshan#112 年前

无效的正则表达式

参与回复

登录后即可参与回复。登录