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;
	}
}
相关推荐
剑之所向1 小时前
DataEase 做大屏,只认 2 种 SQL 格式
数据库·sql·正则表达式
Season4502 天前
C++11之正则表达式使用指南--[正则表达式介绍]|[regex的常用函数等介绍]
c++·算法·正则表达式
北风toto2 天前
正则表达式
正则表达式
除了辣条不吃辣6 天前
ABAP 正则表达式
开发语言·正则表达式·abap·alv
吴声子夜歌7 天前
JavaScript——字符串和正则表达式
开发语言·javascript·正则表达式
曾阿伦7 天前
Python 正则表达式备忘录:判断与提取核心用法
python·正则表达式
小张贼嚣张7 天前
SQL 正则表达式详解:语法、函数与实战案例(MySQL/Oracle通用)
mysql·oracle·正则表达式
Zzzz_my8 天前
正则表达式(RE)
pytorch·python·正则表达式
yhole9 天前
SQL中的REGEXP正则表达式使用指南
数据库·sql·正则表达式
ybdesire11 天前
ReDoS(正则表达式拒绝服务攻击)理解与实测
正则表达式·漏洞