- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我必须编写一个 C++ 正则表达式,但我无法在 regex_match 上获得正确的结果,因为我是 C++ 的新手。测试字符串为:D10A7;让我们说 unsigned_char[] stringToBeTested="D10A7";
我要做的是在 regex_match 之后,我将在两个不同的短变量中提取 10 和 7 以供应用程序使用。 'D' 之后的数字总是两位数,'A' 之后的数字总是是一位数。我的尝试是:
boost::regex re("D([0-9])(/([0-9]))?");
boost::cmatch mr;
if ( boost::regex_match(stringToBeTested, mr, re ) )
{
number = atoi(mr.str(1).c_str()); //Must be 10
axis = atoi(mr.str(2).c_str()); //Must be 7
}
如何为这种情况生成boost::regex re,请详细解释答案。
最佳答案
regex_match
需要完整的字符串匹配。您需要提供一个模式来执行此操作。
boost::regex re("D([0-9]{2})A([0-9])");
在这里,
D
- 匹配 D
([0-9]{2})
- 捕获第 1 组两位数A
- 匹配 A
([0-9])
- 将单个数字捕获到第 2 组。关于c++ - 为什么 regex_match 与我的正则表达式不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43090952/
这个问题在这里已经有了答案: Is gcc 4.8 or earlier buggy about regular expressions? (3 个答案) 关闭 6 年前。 我正在尝试对其中包含方括
#include`` #include `` #include `` using namespace std; int main () { try{ std::regex re("(http|ht
我在 site 上测试了正则表达式 [BCGRYWbcgryw]{4}\[\d\]似乎可以在以下 BBCC[0].GGRY[0].WWWW[soln] 中找到匹配项。它与 BBCC[0] 和 GGRY
我正在尝试编写递归下降解析器,并尝试在用户输入的字符串中搜索正则表达式的匹配项。我正在尝试执行以下操作以尝试理解 C++11 提供的库,但我得到了意想不到的结果。 std::string expre
我正在尝试检查 yyyy-mm-dd 格式的日期字符串的格式。我像这样调用 regex_match 函数: if (regex_match(date, regex("/\d{4}-\d{2}-\d{2
我正在尝试使用 std::regex_match()作为 std::count_if() 中的谓词与 std::vector类成员函数中的元素。但是不知道如何正确地将第二个参数(正则表达式值)绕过到函
这是我的代码: #include #include #include using namespace std; int main () { string test = "COPY" ;
我正在使用 C++ 正则表达式。无法掌握以下编程输出。 #include #include #include #include using namespace std; int main(){
我在 XCode 上使用 C++。我想使用 regex_match 匹配非字母字符,但似乎有困难: #include #include using namespace std; int main(
这个问题在这里已经有了答案: Is gcc 4.8 or earlier buggy about regular expressions? (3 个答案) 关闭 5 年前。 我有这段代码片段,是我从
这是我的部分代码 bool CSettings::bParseLine ( const char* input ) { //_asm INT 3 std::string line (
我试图弄清楚我在这个验证规则上做错了什么,因为它说了这个错误。 验证规则: $this->form_validation->set_rules('username', 'Username', 'tri
在我的代码中,我想根据封闭的 <> 括号处理 stirngs。为此,我想遍历字符串并一个一个地替换括号并根据括号内的内容做一些事情。 string msg = "This is an Example<
目标是:这个 json: {"secretWord1":"private", "something": "\"secretWord2\":\"privateToo\""} 通过 regex_match
这是我的程序: #include "stdafx.h" #include #include #include #include using namespace std; int _tmain(
我必须编写一个 C++ 正则表达式,但我无法在 regex_match 上获得正确的结果,因为我是 C++ 的新手。测试字符串为:D10A7;让我们说 unsigned_char[] stringTo
我有一些我认为应该触发的 boost Regex 代码。我是 boost 的新手,但我对 Regex 有一点了解。这是我正在使用的代码。 re = boost::basic_regex(_T("-+\
我想匹配输入字段中给定的字符串。 A sample data could be "hello" -> returns true or "\"" -> returns true or "this is
我知道: 惰性量词匹配:尽可能少(最短匹配) 还知道构造函数: basic_regex( ..., flag_type f = std::regex_constants::EC
这个问题在这里已经有了答案: Simple std::regex_search() code won't compile with Apple clang++ -std=c++14 (3 个答案)
我是一名优秀的程序员,十分优秀!