diff --git a/libs/regexp/regexp.c b/libs/regexp/regexp.c index 1fdc6c94..f7c2b9c4 100644 --- a/libs/regexp/regexp.c +++ b/libs/regexp/regexp.c @@ -300,6 +300,20 @@ static value regexp_matched_pos( value o, value n ) { } } +/** + regexp_matched_num : 'regexp -> int + Return the total number of matched groups, or -1 if the regexp has not + been matched yet +**/ +static value regexp_matched_num( value o ) { + pcredata *d; + val_check_kind(o,k_regexp); + d = PCRE(o); + if( val_is_null(d->str) ) + return alloc_int(-1); + return alloc_int(d->n_groups); +} + void regexp_main() { id_pos = val_id("pos"); id_len = val_id("len"); @@ -316,6 +330,7 @@ DEFINE_PRIM(regexp_replace_all,3); DEFINE_PRIM(regexp_replace_fun,3); DEFINE_PRIM(regexp_matched,2); DEFINE_PRIM(regexp_matched_pos,2); +DEFINE_PRIM(regexp_matched_num,1); DEFINE_ENTRY_POINT(regexp_main); /* ************************************************************************ */