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?
In reply to Priority of | regex operator by bfdi533
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |