Srinath Avadhanula wrote:

> I think that the newly provided matchlist() function is very useful.
> However, in the following case:
> 
> matchlist('aoasdf', '\v(.)(o)?(.*)') =3D ['aoasdf', 'a', 'o', 'asdf']
> 
> matchlist('aasdf', '\v(.)(o)?(.*)') =3D ['aasdf', 'a']
> 
> In other words, if pattern containing ()? matches but without no occurences
> of an optional group (the second case above), the list is cut off at that
> point.
> 
> I would think that in the latter case, something like
> =09['aasdf', 'a', '', 'asdf']
> would be very nice. Basically, matchlist() if it matches should always
> return a list of the same length as the number of groups as in the pattern
> but with optionally empty strings.
> 
> Does this make sense? This would make parsing things easier.

At least the matching submatches should be returned.  When some of the
last submatches don't match it would still be easy if you can access the
resulting list without having to check if the item is really there.
Thus matchlist() should always return a list with ten items.  Submatches
that didn't match will then have an empty item.

Example: echo matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')
        Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']

-- 
Ten million Linux users can't be wrong!

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://www.ICCF.nl         ///

Reply via email to