如何使用C++;正则表达式查找方括号之间的字符 我有一个C++正则表达式来搜索方括号内的字符,例如如果字符串是x[7:0],我想返回7:0。这就是我的正则表达式的样子- std::regex reg("\[(.*?)\]");

如何使用C++;正则表达式查找方括号之间的字符 我有一个C++正则表达式来搜索方括号内的字符,例如如果字符串是x[7:0],我想返回7:0。这就是我的正则表达式的样子- std::regex reg("\[(.*?)\]");,c++,regex,C++,Regex,当我编译(g++)时,我得到以下警告- ../fixedPointFormatter.cc:30:18:警告:未知转义序列:']' std::regex reg(“[(.*?)”); ^~~~~~~~~~~ 以下内容不返回任何内容 if (regex_search(arg, matches, reg)) { for (int i=1; i<matches.size(); i++) { cout << matches[i] << endl; } } if(

当我编译(g++)时,我得到以下警告-

../fixedPointFormatter.cc:30:18:警告:未知转义序列:']' std::regex reg(“[(.*?)”); ^~~~~~~~~~~

以下内容不返回任何内容

if (regex_search(arg, matches, reg)) {
 for (int i=1; i<matches.size(); i++) {
   cout << matches[i] << endl;
 }
}
if(正则表达式搜索(arg,matches,reg)){

对于(int i=1;i,正则表达式需要使用
\
[
]
进行转义。但是,要将其提供给正则表达式,需要对字符串中的
\
进行转义

std::regex reg("\\[(.*?)\\]");

不客气,@RajatMitra。很高兴我能帮上忙。