草庐IT

regex-compat

全部标签

c++ 正则表达式使用 regex_search() 提取所有子字符串

我是C++正则表达式的新手。我有一个字符串“{1,2,3}”,我想提取数字123。我想我应该使用regex_search但它失败了。#include#include#includeusingnamespacestd;intmain(){strings1("{1,2,3}");strings2("{}");smatchsm;regexe(R"(\d+)");cout结果:{1,2,3}size:1the1thmatch:1 最佳答案 std::regex_search仅在找到第一个匹配项后返回。什么std::smatch给你的是正则表

c++ - 在 C++ 中使用 boost regex 提取子匹配

我正在尝试使用boost正则表达式从文本文件中提取子匹配项。目前我只返回第一个有效行和整行而不是有效的电子邮件地址。我尝试使用迭代器并使用子匹配,但我没有成功。这是当前代码:if(Myfile.is_open()){boost::regexpattern("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$");while(getline(Myfile,line)){string::const_iteratorstart=line.begin();string::const_iteratorend=

c++ - 正则表达式:boost::xpressive 与 boost::regex

我想在C++中做一些正则表达式,所以我查看了interwebz(是的,我是C++的初学者/中级)并发现thisSOanswer.我真的不知道在boost::regex和boost::xpressive之间选择什么。有什么优点/缺点?我还读到与boost::regex相对的boost::xpressive是一个仅限header的库。在Linux和Windows上静态编译boost::regex难吗(我几乎总是写跨平台的应用程序)?我也对编译时间的比较感兴趣。我有一个使用boost::xpressive的当前实现,我对编译时间不太满意(但我没有与boost::regex的比较)。当然,我也

c++ - 从 std::regex 中提取原始正则表达式模式

我有一个函数试图将给定的字符串与给定的正则表达式模式进行匹配。如果它不匹配,它应该创建一个指示这种情况的字符串,并包括它失败的正则表达式模式和字符串的内容。类似的东西:boolvalidate_content(conststd::string&str,conststd::regex&pattern,std::vector&errors){if(false==std::regex_match(str,pattern)){std::stringstreamerror_str;//error_str但是,正如您所见,注释掉的行提出了一个挑战:是否有可能恢复正则表达式对象的原始模式?显然有一种

c++ - 简单的 std::regex_search() 代码无法使用 Apple clang++ -std=c++14 编译

这是MCVE:#include#includestd::strings(){return"test";}intmain(){staticconststd::regexregex(R"(\w)");std::smatchsmatch;if(std::regex_search(s(),smatch,regex)){std::cout它编译得很好:$clang++-std=c++11main.cpp但不是:$clang++-std=c++14main.cpp后一种情况下的错误信息(使用-std=c++14):main.cpp:14:9:error:calltodeletedfunction'

c++ - Boost.Regex 与 C++11 正则表达式

有人能解释一下两者之间的区别吗?现在学习哪个更好?知识如何从一个转移到另一个,反之亦然? 最佳答案 boost正则表达式库将它变成了C++0x,所以我猜它会慢慢从boost中删除。但是,使用boost很好,因为您仍然可以在不支持C++0x的编译器中使用它。所以这真的取决于你。 关于c++-Boost.Regex与C++11正则表达式,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/

c++ - 智能感知 : the object has type qualifiers that are not compatible with the member function

我有一个名为Person的类:classPerson{stringname;longscore;public:Person(stringname="",longscore=0);voidsetName(stringname);voidsetScore(longscore);stringgetName();longgetScore();};在另一个类(class),我有这个方法:voidprint()const{for(inti=0;i这是人的声明:staticconstintsize=8;Personpeople[size];当我尝试编译它时,我得到了这个错误:IntelliSense

regex - ExpressJS 路由正则表达式

我有路线:app.get('/:id',routes.action);它工作正常,但我需要跳过robot.txt和其他(人类....)我创建正则表达式(仅字符或数字):/^[a-z]{0,10}$/我怎样才能只路由匹配这个正则表达式的id? 最佳答案 将正则表达式放在括号中,如下所示:app.get('/:id(^[a-z]{0,10}$)',routes.action); 关于regex-ExpressJS路由正则表达式,我们在StackOverflow上找到一个类似的问题:

javascript - Firebase + Node.js : Error: The XMLHttpRequest compatibility library was not found

Firebase+Node.js在iOS上:已安装Node.jsnpminstallfirebase--saveNode测试.js其中test.js是一个连接Firebase的非常简单的脚本:varfirebase=require("firebase/app");require("firebase/auth");varconfig={...};varapp=firebase.initializeApp(config);//Worksfinefirebase.auth().signInWithEmailAndPassword(…);//Throwserror抛出的错误是Error:The

regex - Node.js 解析字符串中的数字

给定一个字符串,如:Recipient:test@test.comAction:failedStatus:5.0.0(permanentfailure)Diagnostic:No只有在Status:之后,我才能获得“5.0.0”和“永久失败”??谢谢 最佳答案 varregex=/Status:([0-9\.]+)\(([a-zA-Z]+)\)/varresult=string.match(regex);varstatusNumber=result[1];varstatusString=result[2];如果您希望这些值中有其他字