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;
	}
}
相关推荐
特立独行的猫a2 天前
[鸿蒙PC三方库移植] 移植PCRE正则表达式库到鸿蒙PC平台的完整实践
华为·正则表达式·harmonyos·移植·pcre
独隅2 天前
Linux 正则表达式 的简介
linux·mysql·正则表达式
Maggie_ssss_supp3 天前
Linux-正则表达式
linux·运维·正则表达式
IT陈图图4 天前
基于 Flutter × OpenHarmony 图书馆管理系统之构建借阅记录模块
flutter·正则表达式·openharmony
WHOVENLY4 天前
揭秘正则表达式的基础语法与应用
开发语言·javascript·正则表达式
IT陈图图5 天前
基于 Flutter × OpenHarmony 的正则表达式测试器开发实战
flutter·正则表达式·openharmony
不平衡的叉叉树7 天前
我们遇到了正则表达式的灾难性回溯问题
java·正则表达式
Meteors.7 天前
正则表达式及其常见使用(Kotlin版)
正则表达式
至此流年莫相忘7 天前
正则表达式之捕获分组——Python篇
python·正则表达式
西红市杰出青年7 天前
crawl4ai------AsyncPlaywrightCrawlerStrategy使用教程
开发语言·python·架构·正则表达式·pandas