Hi Khaled.
I noticed that the $regmlex identifier returns 0 instead of null for a group that has not captured anything. I believe that this behavior is not the most appropriate.
Example:
//noop $regex(test a regmlex_identifier,/([^\s]+)?(regmlex)([^\s]+)?/) | echo -a Number of groups captured: $regmlex(1,0) - Group 1: $regmlex(1,1) - Group 2: $regmlex(1,2) - Group 3: $regmlex(1,3)
Will print: Number of groups captured: 2 - Group 1: 0 - Group 2: regmlex - Group 3: _identifier
Example 2:
//noop $regex(test a 0regmlex_identifier,/([^\s]+)?(regmlex)([^\s]+)?/) | echo -a Number of groups captured: $regmlex(1,0) - Group 1: $regmlex(1,1) - Group 2: $regmlex(1,2) - Group 3: $regmlex(1,3)
Will print: Number of groups captured: 3 - Group 1: 0 - Group 2: regmlex - Group 3: _identifier
It may not be a bug, but just the way you've decided to treat it. However, from my point of view, if it is not a bug, the return value would have to be null for an uncaught group.