MFC使用正则表达式基础步骤

使用正则表达式基础步骤

①头文件包含 #include

②明确声明正则表达式

cpp 复制代码
std::regex reg("(((\\d)|([1-9]\\d)|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d)|([1-9]\\d)|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))");

更多正则表达式可查阅:https://blog.csdn.net/Next_Second/article/details/126696589

③CString 转string

cpp 复制代码
CString strIP = _T("127.0.0.1");
CT2CA IpTem(strIP);
std::string Ip(IpTem);

④进行匹配

cpp 复制代码
std::regex_match(Ip, reg)//匹配上返回true,否则返回false

完整函数

cpp 复制代码
BOOL CheckIPValid( CString strIP )
{
	std::regex reg("(((\\d)|([1-9]\\d)|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d)|([1-9]\\d)|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))");
	CT2CA IpTem(strIP);
	std::string Ip(IpTem);
	if (std::regex_match(Ip, reg))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
相关推荐
除了辣条不吃辣3 天前
ABAP 正则表达式
开发语言·正则表达式·abap·alv
吴声子夜歌4 天前
JavaScript——字符串和正则表达式
开发语言·javascript·正则表达式
曾阿伦4 天前
Python 正则表达式备忘录:判断与提取核心用法
python·正则表达式
小张贼嚣张4 天前
SQL 正则表达式详解:语法、函数与实战案例(MySQL/Oracle通用)
mysql·oracle·正则表达式
Zzzz_my5 天前
正则表达式(RE)
pytorch·python·正则表达式
yhole6 天前
SQL中的REGEXP正则表达式使用指南
数据库·sql·正则表达式
ybdesire8 天前
ReDoS(正则表达式拒绝服务攻击)理解与实测
正则表达式·漏洞
weixin_433179338 天前
python - 正则表达式Regex
python·正则表达式
wayz1110 天前
正则表达式:从入门到精通
java·python·正则表达式·编辑器
梨落秋霜10 天前
Python入门篇【正则表达式】
python·mysql·正则表达式