我现在正在使用VC++ 2010,但是VC++ 2010的syntax_option_type
只包含以下选项:
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库。
有许多用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
风格?是否有一些工具可以实现这一点?任何帮助都将不胜感激!