$rule = rx :w / plane ::: (\d+) | train ::: (\w+) | auto ::: (\S+) / ; $rule = rx :w /[ plane :: (\d+) | train :: (\w+) | auto :: (\S+) ]/ ;
On Thu, May 12, 2005 at 02:29:24PM -0400, Aaron Sherman wrote: > On Thu, 2005-05-12 at 13:44, Patrick R. Michaud wrote: > > On Thu, May 12, 2005 at 12:53:46PM -0400, Aaron Sherman wrote: > > > Your two examples fail in the same way because of the fact that the > > > group IS the whole rule. > > > > False. In the first case the group is the whole rule. In the second > > case the group would not include the (implied) '.*?' at the start of > > the rule. > > That cannot be true. If it were, then: > s/[a]// > and > s/a// > would replace different things, and they MUST NOT. No, /[a]/ is still the same as /a/ here -- I'm not discussing that at all, nor am I implying any special [] or rule semantics. I'm simply referring to the fact that the rule is free to step across the characters in the string, same as you pointed out. Let me backtrack(!) and try a slightly different example, first using a group and (::) $r1 = rx /[abc :: def | ghi :: jkl | mn :: op]/; "abcdef" ~~ $r1 # matches "abcdef" "xyzghijkl" ~~ $r1 # matches "ghijkl" "xyzabcghijkl" ~~ $r1 # matches "ghijkl" Why does the last one match? Because it fails the group but doesn't fail the rule -- i.e., the rule is still free to advance its initial pointer to the next character and try again. Contrast this with: $r2 = rx /abc ::: def | ghi ::: jkl | mn ::: op/; "abcdef" ~~ $r1 # matches "abcdef" "xyzghijkl" ~~ $r1 # matches "ghijkl" "xyzabcghijkl" ~~ $r1 # fails! This one fails, because once we match the "abc", we're commited to completing the match or failing the rule altogether. Does this work to convince you that the two expression are indeed different? Pm