[英]Pcre php regex equal in c++
hello this is pcre regex (php regex) 你好,这是pcre regex(php regex)
/\h*(.*?)\h*[=]\h*("(.*?(?:[\\\\]".*?)*)")\h*([,|.*?])/
this regex work for this string 此正则表达式适用于此字符串
data1 = "value 1", data2 = "value 2", data3 = " data4(" hey ") ",
and get 并得到
data, data2, data3
val, val2, data4("val3")
what is this regex equal in c++ regex ? 这个正则表达式在c ++正则表达式中等于什么?
You should replace \\h
with \\s
and use \\\\
inside a raw string literal. 您应将
\\h
替换为\\s
并在原始字符串文字中使用\\\\
。
Refer to the following example code: 请参考以下示例代码:
#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;
}
See IDEONE demo and a JS (ECMA5) regex demo 请参阅IDEONE演示和JS(ECMA5) 正则表达式演示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.