在C++中使用非常简单的表达式regex_error
regex_error in C++ with really simple expression
我有一组字符串,比如这个紫罗兰+2,橙色-3等等。这是一种命名颜色的方法。我想使用以下代码获取regex的颜色、操作和编号:
int parseColor(string color){
smatch sm;
int ret = -1;
if (regex_match(color,sm,regex("(.*)([+-])(.*)")))
ret = s_colors[sm[1].str()]+s_colors[sm[2].str()]*atoi(sm[3].str().c_str());
return ret;
}
其中s_colors是一个映射,它将每种颜色与一个整数值相匹配,将+、-符号与+1和-1相匹配。
我也试过用\\+和\\-来修饰+-符号,但也不起作用。每次运行时,我都会得到regex_error。在ruby中尝试这个似乎有效,所以…我不确定regex的错误是什么。
Gcc 4.8.2不支持regex。您需要4.9
相关文章:
- 使用 boost::regex 从目录中获取带有一些正则表达式的文件名称时出现意外输出
- 你能防止 std::regex 在无效表达式上抛出异常吗?
- 使用 boost::regex (c++) 比较两个正则表达式
- C++正则表达式Visual Studio Community 2015给出<regex>意想不到的结果
- std::regex对于用户定义的表达式安全吗?
- #include < regex.h> 用于创建正确正则表达式的问题
- 以下等级表达式不适合Boost Regex
- Regex表达式无效
- Boost Regex中的命名子表达式错误
- Regex分组与C++11正则表达式库匹配
- 将Javascript正则表达式模式转换为C++std::regex的规则
- 您可以将C++ std::regex 表达式转换为 C# 表达式吗?
- 使用 Boost::regex 进行正则表达式组匹配
- 通过 std::regex 从数学表达式中制作树
- C++中的Regex,从正则表达式中获取文本任何部分的字符串
- Regex表达式提取括号内的所有内容
- C++中的std::regex表达式
- 如果给定空白regex表达式,则regex_replace中的C++Mac OS无限循环
- 从文件中获取行并用作正则表达式(regex)
- Boost表达式regex会导致垃圾字符