加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式

发布时间:2020-12-13 22:30:58 所属栏目:百科 来源:网络整理
导读:在大神的基础上进行修改的代码,判断邮箱的正确格式 本代码在dev上边不能运行,在vc6.0上边也不能运行(在网上搜的说是要导入boost库),感觉麻烦就在VS2013上边运行了 #include "stdafx.h"#includeregex#includestring#includecstdlib#includeiostreamusing

在大神的基础上进行修改的代码,判断邮箱的正确格式

本代码在dev上边不能运行,在vc6.0上边也不能运行(在网上搜的说是要导入boost库),感觉麻烦就在VS2013上边运行了

#include "stdafx.h"
#include<regex>
#include<string>
#include<cstdlib>
#include<iostream>
using namespace std;
int main(){
	string email_adress;
	string username,yuming;

	regex pattern("([0-9A-Za-z-_.]+)@([0-9a-z]+.[a-z]{2,3}(.[a-z]{2})?)");
	while (true){
		cout << "请输入你所要测试的邮箱:" << endl;
		cout << "如果想要结束请输入exit..." << endl;
		cin >> email_adress;
		if (regex_match(email_adress,pattern)){
			cout << "你输入的邮箱格式正确!" << endl;
			username = regex_replace(email_adress,pattern,string("$1"));
			yuming = regex_replace(email_adress,string("$2"));
			cout << "你输入的用户名为:" << username << endl;
			cout << "你输入的域名为:" << yuming << endl;
		}
		else if ((email_adress == "exit")){
			cout << "已安全退出!" << endl;
			break;
		}
		else
			cout << "你输入的邮箱不合法!" << endl;
		cout << endl << endl;
	}
	return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读