Email Parser 邮件地址解析器, 从给定内容中抓取邮件地址&自动排除重复&过滤指定邮箱

Categories: Flex; Tagged with: ; @ September 10th, 2010 21:41

功能介绍:

从给定的文字内容中 解析Email地址, 并显示出来. 同时支持QQ提取.

原理与代码:

Update: 正则表达式已更正, 参考: http://liguoliang.com/2011/validate-email-regex/

Flex使用正则表达式搜索内容

核心代码:

/** 当按下解析按钮时响应. */
		protected function onButtonParse(event:MouseEvent):void {
			var sourceStr:String = StringUtils.trim(textSource.text);
			var resultMap:Object = new Object();
			if(StringUtils.isEmptyString(sourceStr)) {
				Alert.show("请先输入要解析的字符");
				return;
			}

			textOutput.text = "";

			var patternEmail:RegExp = new RegExp("(([\\w\\.-]{1,})@([\\w-]{1,}\\.+[a-zA-Z]{2,}))", "g");
			var resultsRawEmail:Array = sourceStr.match(patternEmail);
			for each(var resultEmail:String in resultsRawEmail) {
				resultMap[resultEmail] = resultEmail;
			}

			if(checkBoxQQ.selected) {
				TextAreaUtils.appendMessageAndScrollProperly(textOutput, "本次解析会自动解析QQ号码, 并追加@qq.com");
				var patternQQ:RegExp = new RegExp("([1-9][\\d]{4,})", "g");
				var resultsRawQQ:Array = sourceStr.match(patternQQ);

				for each(var result:String in resultsRawQQ) {
					resultMap[result+ "@qq.com"] = result + "@qq.com";
				}
			}

			TextAreaUtils.appendMessageAndScrollProperly(textOutput, "解析完毕, 共获得: " + ObjectUtils.getSize(resultMap));

			for(var key:String in resultMap) {
				TextAreaUtils.appendMessageAndScrollProperly(textOutput, resultMap[key] + ", ", false);
			}
		}

		/** 当Linkbutton点击时响应. */
		protected function onLinkbuttonClick(event:MouseEvent):void {
			navigateToURL(new URLRequest("http://liguoliang.com"));
		}

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.