现在我使用的是 VC++ 2010,但是syntax_option_type
VC++ 2010 只包含以下选项:
static const flag_type icase = regex_constants::icase;
static const flag_type nosubs = regex_constants::nosubs;
static const flag_type optimize = regex_constants::optimize;
static const flag_type collate = regex_constants::collate;
static const flag_type ECMAScript = regex_constants::ECMAScript;
static const flag_type basic = regex_constants::basic;
static const flag_type extended = regex_constants::extended;
static const flag_type awk = regex_constants::awk;
static const flag_type grep = regex_constants::grep;
static const flag_type egrep = regex_constants::egrep;
它不包含 perl_syntax_group(Boost 库有选项)。但是,我不想使用 Boost Library。
有很多用 Perl 编写的正则表达式,所以我想将现有的 Perl 正则表达式转换为ECMAScript
(或 VC++ 2010 支持的任何一个)。转换后,我可以直接在 VC++ 2010 中使用等效的正则表达式,而无需使用第三方库。
一个例子:
const boost::tregex e(__T("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z"));
const CString human_format = __T("$1-$2-$3-$4");
CString human_readable_card_number(const CString& s)
{
return boost::regex_replace(s, e, human_format);
}
CString credit_card_number = "1234567887654321";
credit_card_number = human_readable_card_number(credit_card_number);
assert(credit_card_number == "1234-5678-8765-4321");
在上面的例子中,我想做的是转换和e
样式表达式。format
ECMAScript
是否有可能找到将所有 Perl 正则表达式转换为ECMAScript
样式的通用方法?有一些工具可以做到这一点吗?
任何帮助将不胜感激!