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;
	}
}
相关推荐
IT陈图图19 小时前
基于 Flutter × OpenHarmony 图书馆管理系统之构建借阅记录模块
flutter·正则表达式·openharmony
WHOVENLY20 小时前
揭秘正则表达式的基础语法与应用
开发语言·javascript·正则表达式
IT陈图图2 天前
基于 Flutter × OpenHarmony 的正则表达式测试器开发实战
flutter·正则表达式·openharmony
不平衡的叉叉树4 天前
我们遇到了正则表达式的灾难性回溯问题
java·正则表达式
Meteors.4 天前
正则表达式及其常见使用(Kotlin版)
正则表达式
至此流年莫相忘4 天前
正则表达式之捕获分组——Python篇
python·正则表达式
西红市杰出青年4 天前
crawl4ai------AsyncPlaywrightCrawlerStrategy使用教程
开发语言·python·架构·正则表达式·pandas
噎住佩奇5 天前
正则表达式(Regex)入门
运维·正则表达式
Irene19916 天前
JavaScript 正则表达式 API 总结
正则表达式
linuxxx1106 天前
正则匹配应用小案例
数据库·正则表达式