c++ - How to use <regex> in C++11 -
i'm trying use regular expression accept strings have sequences like
ifelseifelseififif
so every else needs if, not every if needs else. know pen , paper simple regular expression ((if)*+(ifelse)*)*
.now i'm not sure if i'll able library i've never used before. possible accept or reject string based on regular expression 1 wrote above?
i wrote sample feet wet , don't understand why returns false. isn't regex_search() supposed find substring matches? snippet prints nope every time.
#include <regex> #include <iostream> using namespace std; int main(){ string sequence="ifelse"; regex rx("if"); if(regex_search(sequence.begin(),sequence.end(),rx)){ cout<<"match found"<<endl; }else{ cout<<"nope"<<endl; } }
i'm using g++ 4.7 , have tried compiling both g++ -std=gnu+11 reg.cpp
, g++ -std=c++11 reg.cpp
if compiling g++ may because regex not supported yet. see here current c++11 status in g++.
Comments
Post a Comment