bfdi533 has asked for the wisdom of the Perl Monks concerning the following question:
I have a recent issue that required a regex with the or '|' operator and was confused on the output.
Here is some sample input:
this_line_'aaa|bbb|ccc|ddd|eee'_is_terminated this_line_'aaa|bbb|ccc|ddd|eee'_is_terminated this_line_'aaaaa|bbbbb|ccccc|ddddd|eeeee'_is_... this_line_'aaaaa|bbbbb|ccccc|ddddd|eeeee'_is_... this_line_'aaaaaa|bbbbbb|cccccc|dddddd|eeeeee... this_line_'aaaaaa|bbbbbb|cccccc|dddddd|eeeeee...
I am using the following code to find and extract part of the line:
while (<>) { $inline = $_; ($data,$trail) = $inline =~ /this_line_'(.*)('_|\.\.\.); print $data . "\n"; }
What I am getting is the following output:
aaa|bbb|ccc|ddd|eee aaa|bbb|ccc|ddd|eee aaaaa|bbbbb|ccccc|ddddd|eeeee'_is_ aaaaa|bbbbb|ccccc|ddddd|eeeee'_is_ aaaaaa|bbbbbb|cccccc|dddddd|eeeeee aaaaaa|bbbbbb|cccccc|dddddd|eeeeee
The first two lines I understand as they match the regex with only one of the second conditions. The last two lines I understand as well as they match the regex with only one of the second conditions.
However, the middle two lines I do not understand. The second regex condition with the '|' in it would seem to me to eval left to right. Rather, it seems to be being evaluated right to left. Maybe it is not really right to left but some other way.
Can anyone help me to understand the priority of the conditions in a regex where the or ('|') operator is concerned?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Priority of | regex operator
by eff_i_g (Curate) on Apr 26, 2006 at 22:54 UTC | |
by bfdi533 (Friar) on Apr 27, 2006 at 15:56 UTC | |
by eff_i_g (Curate) on Apr 27, 2006 at 16:31 UTC | |
|
Re: Priority of | regex operator
by rhesa (Vicar) on Apr 26, 2006 at 23:03 UTC |