Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Pcre php regex等于c++;_C++_Regex - Fatal编程技术网

C++ Pcre php regex等于c++;

C++ Pcre php regex等于c++;,c++,regex,C++,Regex,你好,这里是pcre正则表达式(php正则表达式) 此正则表达式适用于此字符串 data1 = "value 1", data2 = "value 2", data3 = " data4(" hey ") ", 得到 data, data2, data3 val, val2, data4("val3") >在C++正则表达式中,这个正则表达式是什么?< p>应该用 < 替换 \h代码>代码,并在原始字符串文字内使用 \/>代码> 请参阅以下示例代码: #include <

你好,这里是pcre正则表达式(php正则表达式)

此正则表达式适用于此字符串

data1 = "value 1",   data2 = "value 2",  data3 = " data4(" hey ") ",
得到

data, data2, data3
 val, val2, data4("val3") 

>在C++正则表达式中,这个正则表达式是什么?

< p>应该用<代码> < <代码>替换<代码> \h代码>代码,并在原始字符串文字内使用<代码> \/>代码>

请参阅以下示例代码:

#include <string>
#include <iostream>
#include <regex>
using namespace std;

int main() {
    std::string pat = R"(\s*(.*?)\s*=\s*(\"(.*?(?:[\\]\".*?)*)\")\s*([,|.*?]))";
    std::regex r(pat);
    std::cout << pat << "\n";

    std::string s = R"(data1 = "value 1",   data2 = "value 2",  data3 = " data4(" hey ") ",)";
    std::cout << s << "\n";
    for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
                             i != std::sregex_iterator();
                             ++i)
    {
        std::smatch m = *i;
        std::cout << "Capture 1: " << m[1].str() << " at Position " << m.position(1) << '\n';
        std::cout << "Capture 3: " << m[3].str() << " at Position " << m.position(3) << '\n';
    }
    return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main(){
std::string pat=R“(\s*(.*?)\s*=\s*(\”(.*(?:[\\]\”*?)*)\”)\s*([,|.*)))”;
标准:正则表达式r(pat);

std::不能将
\h
替换为
\s
。如果使用原始字符串,请使用
\\\
而不是
\\\\
。请参阅。
#include <string>
#include <iostream>
#include <regex>
using namespace std;

int main() {
    std::string pat = R"(\s*(.*?)\s*=\s*(\"(.*?(?:[\\]\".*?)*)\")\s*([,|.*?]))";
    std::regex r(pat);
    std::cout << pat << "\n";

    std::string s = R"(data1 = "value 1",   data2 = "value 2",  data3 = " data4(" hey ") ",)";
    std::cout << s << "\n";
    for(std::sregex_iterator i = std::sregex_iterator(s.begin(), s.end(), r);
                             i != std::sregex_iterator();
                             ++i)
    {
        std::smatch m = *i;
        std::cout << "Capture 1: " << m[1].str() << " at Position " << m.position(1) << '\n';
        std::cout << "Capture 3: " << m[3].str() << " at Position " << m.position(3) << '\n';
    }
    return 0;
}