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;
	}
}
相关推荐
linux_cfan1 天前
**标题:20年研发经验总结:Notepad++ 高效文本排版与正则表达式进阶指南**
正则表达式·notepad++
SuperEugene2 天前
前端正则表达式完全指南:从手写不出到随手就来
前端·正则表达式
salt3 天前
HALCON字符串处理实战:从基础操作到正则表达式应用
正则表达式·halcon·工业视觉·字符串处理
半新半旧3 天前
正则表达式
正则表达式
程序员Sonder3 天前
黑马java----正则表达式(一文弄懂)
java·正则表达式·新人首发
doris82043 天前
Python 正则表达式 re.findall()
java·python·正则表达式
python_chai3 天前
正则表达式从入门到实战:Python高效处理文本的终极秘籍
正则表达式·re模块·文本处理·pothon·贪婪匹配
Mrliu__3 天前
Python高级技巧(六):正则表达式
开发语言·python·正则表达式
YC运维3 天前
Shell 正则表达式完全指南
正则表达式