在C++中创建JavaScript正则表达式 是否可以在C++中创建一个ReXEP JavaScript对象?我只是好奇而已

在C++中创建JavaScript正则表达式 是否可以在C++中创建一个ReXEP JavaScript对象?我只是好奇而已,c++,regex,C++,Regex,例如: const myCLib = require('myCLib'); myCLib("/\\s/", "g"); => return regex object /\g/g 是,这是C++ C++标准的一部分,不需要额外的库。正则表达式的默认语法与ECMAScript的JavaScript正则表达式语法相同 #include <regex> // Note that construction of the regex can be QUITE expensive, an

例如:

const myCLib = require('myCLib');
myCLib("/\\s/", "g"); => return regex object /\g/g

<>是,这是C++ C++标准的一部分,不需要额外的库。正则表达式的默认语法与ECMAScript的JavaScript正则表达式语法相同

#include <regex>

// Note that construction of the regex can be QUITE expensive, and should
// not be done often if you care even a little about performance. Regexes
// are commonly created at global scope.
const std::regex my_regex{"\\s"};

// Raw strings are sometimes more readable...
const std::regex my_regex{R"(\s)"};

/G修改器行为是通过使用正则表达式不同的,参见

性能取决于所使用的C++实现,以及您正在解决的特定问题。我可以想到三种主要的C++11实现,它们各不相同。您可以始终使用第三方正则表达式库或编译正则表达式来编写代码,例如使用Ragel,如果您认为值得付出努力,它可以生成非常高性能的解析器。