vc6.0下 使用boost regex正则表达式匹配带中文的任意字符
来源:互联网 发布:nginx tcp反向代理 编辑:程序博客网 时间:2024/06/05 12:07
源代码:
boost::cmatch result2;
// 特殊字符"."和"\"从字符串转为正则表达式需要加"\",在正则表达式中要单纯的表示反斜杠字符页需要加"\",所以要匹配".\ "应该写为"\\.\\\\"
CString csReg = "\\.\\\\(\\S+)\\.[tsp|enx|ts|tc|tsw]"; // 匹配 以 .\ 开头 .tsp|.enx|.ts|.tc|.tsw结尾的任意字符串,并获取匹配到的字符串
boost::regex regText;
regText = csReg;
string sToMatch((LPCTSTR)csSourceStr);
if ( !boost::regex_search(sToMatch,result2,regText))
{
return FALSE;
}
//下标从1开始, result2[0] 不正确
for (size_t i = 1; i < result2.size(); ++i)
{
if (result2[i].matched)
{
std::string strIs(result2[i].first,result2[i].second);
csDestStr = strIs.c_str();
}
}
return TRUE;
测试代码未进行宽字符转换:
BOOL CSelectTestInstance::regexMatchStr(const CString &csSourceStr,CString &csDestStr)
{
boost::cmatch result2;
boost::regex regText("[A-Za-z0-9_\x80-\xFF]+");//如果匹配的字符串为./硬测自动化/自动化.tc ,匹配的结果只能匹配到“硬测自动化”,不知为何
string sToMatch((LPCTSTR)csSourceStr);//csSourceStr = ./硬测自动化_A_1.tc
if ( !boost::regex_search(sToMatch,result2,regText))
{
return FALSE;
}
for (size_t i = 0; i < result2.size(); ++i)
{
if (result2[i].matched)
{
std::string strIs(result2[i].first,result2[i].second);
csDestStr = strIs.c_str();
}
}
return TRUE;
}
- vc6.0下 使用boost regex正则表达式匹配带中文的任意字符
- java使用正则表达式(regex)匹配中文
- VC6.0下配置boost库使用正则表达式
- VC6.0下配置boost库使用正则表达式
- VC6.0下配置boost库使用正则表达式
- VC6.0下配置boost库使用正则表达式
- VC6.0下配置boost库使用正则表达式
- 转贴:VC6.0下配置boost库使用正则表达式
- VC6.0下配置boost库使用正则表达式
- VC6.0下配置boost库使用正则表达式
- VC6.0下配置boost库使用正则表达式
- VC6.0下配置boost库使用正则表达式
- 正则表达式 匹配任意长度的字符
- java匹配任意字符的正则表达式
- 正则表达式匹配任意字符
- 正则表达式:匹配任意字符
- 正则表达式匹配任意字符
- 正则表达式匹配任意字符
- jquery 找到当前可见的元素并切换显示
- 工厂三兄弟之抽象工厂模式(三)
- ubuntu下c/c++开发环境配置
- socket阻塞,非阻塞,同步,异步的区别
- java后台写javascript代码
- vc6.0下 使用boost regex正则表达式匹配带中文的任意字符
- 工厂三兄弟之抽象工厂模式(四)
- myeclipse中配置多个tomcat实例
- dijstra算法
- MFC程序启动步骤
- 动态分配内存与悬空指针
- JAVA项目引用文件路径问题
- 工厂三兄弟之抽象工厂模式(五)
- openwrt升级命令