我正在使用 boost regex 编写一个日期解析器,我记得(模糊地)boost 允许 regex 组合。作为我在这里寻找的示例是 Perl 中的示例代码:
my $year = qr/\d{1,4}(?:\d\(?B\.C\.\)?)?/;
my $gmonth = qr/(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)/i;
my $fmonth = qr/(?:VEND|BRUM|FRIM|NIVO|PLUV|VENT|GERM|FLOR|PRAI|MESS|THER|FRUC|COMP)/i;
my $hmonth = qr/(?:TSH|CSH|KSL|TVT|SHV|ADR|ADS|NSN|IYR|SVN|TMZ|AAV|ELL)/i;
my $month = qr/(?:$gmonth|$fmonth|$hmonth)/i;
my $day = qr/\d{1,4}/;
my $DE = qr/(?:\@\#DHEBREW\@|\@\#DROMAN\@|\@\#DFRENCH_R\@|\@\#DGREGORIAN\@|\@\#DJULIAN\@|\@\#DUNKNOWN\@)/;
my $DR = qr/(?:AFT|BEF)\s/i;
my $DA = qr/(?:ABT|CAL|EST)\s/i;
my $DI = qr/INT\s/i;
my $prefix = qr/(?:$DR|$DA|$DI)/i;
my $date = qr/$prefix?(?:$DE\s)?(?:$day\s)?(?:$month\s)?$year/;
my $date_p = qr/FROM\s$date\sTO\s$date/i;
my $date_f = qr/FROM\s$date/i;
my $date_t = qr/TO\s$date/i;
my $date_r = qr/BET\.?\s$date\s(?:AND|-)\s$date/i;
my $GED_date = qr/(?:$date|$date_p|$date_r|$date_f|$date_t)/;
while (<DATA>) {
next if /DATE\s$GED_date/;
print $_;
}
正如你所看到的,构图是非常必要的。这只是为了生成一个正则表达式来测试“合法性”。所以我的问题几乎是如何使用 boost 做类似的事情?指针或链接会很好。我可以从中推断出的小例子非常好。与此同时,我将继续阅读提升书籍!