Euphoria
Ticket #362:
Non existent group case must be documented and handled
-
Reported by
SDPringle
Nov 10, 2010
Non existent group case must be documented and handled in regex routines.
For example: `(Hello)?( World)?` Empty string "" will match with {1,1} for the entire match and {0,0} for each of the captured groups that don't exist. Before we had always assumed all the groups would exist, if there were a match. This assumption is false.
Details
1. Comment by jimcbrown
Nov 10, 2010
I don't know, Shawn said this was fixed in a different ticket but left this one open. I'm just guessing here.
2. Comment by jeremy
Nov 10, 2010
How this should have been entered:
include std/regex.e as re
? re:find(re:new(`(Hello)?( World)?`), "")
The output is not as desired, it is:
{
{
{1, 0}
}
}
3. Comment by jeremy
Nov 10, 2010
I think the output is wrong. I am undecided on what the right output should be, there are many choices but none are 1,0
4. Comment by jeremy
Nov 10, 2010
Oh, I do not think it's going to be possible to give all the groups regardless if matched or not simply because we do not get that information back from PCRE, IIRC. I think the best case may be to return 0 from find if not found.
5. Comment by SDPringle
Nov 10, 2010
The issue is the case where groups are absent is not documented well. I am putting some tests up soon.
Now, on the one hand. `(Hello)?(World)?` has two groups in it. So I expected re:find to give you a three element sequence and most of the time it would but if you match this with "" you see that Hello and World groups don't exist and we learned from ticket:350 that {0,0} represents a non-existing group. Therefore thinking this should be something like {{1,0},{0,0},{0,0}}, I was surprised to see {{1,0}}.
It seems to me the rule is if your groups indeces end in {0,0} they are truncated off.
6. Comment by jimcbrown
Nov 11, 2010
The result of discussion on the dev list is that this is considered correct, and thus, fixed.
http://sourceforge.net/mailarchive/forum.php?thread_name=4CDADDC4.1050508%40cowgar.com&forum_name=rapideuphoria-develop
Also assigning to 4.1.0 milestone.
7. Comment by SDPringle
Nov 11, 2010
confirmed fixed.