gpt4 book ai didi

c++ - boost::xpressive 查看序列的开头

转载 作者:太空狗 更新时间:2023-10-29 21:27:03 26 4
gpt4 key购买 nike

我正在使用 boost::xpressive 来解析我的文本文件。我想看看是否仅当该行以“#”开头(多次)。

我正在使用下面的代码

std::string str1 = "## this could be my line";
sregex rex1 = sregex::compile("^#+");
smatch result1;
if(regex_match(str1,result1,rex1){
std::cout << result1[0] << '\n';
}else{
std::cout << "match not found!\n";
}

但我总是收到“找不到匹配项!”,即使行以 # 开头也是如此。有人可以帮我吗?

顺便说一句,谁也能帮我用 boost::xpressive 'bos' 写 rex1 语句?

谢谢!阿伊莎

最佳答案

使用regex_search而不是 regex_match

下面是rex1 的静态 xpressive 语法:

bos >> +as_xpr('#');

关于c++ - boost::xpressive 查看序列的开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10114080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com