Consider the following rule:
$rule={"Period ID"|p:"Period":>p};
This rule will match "Period ID"
and "Period"
. When it matches "Period"
it returns "Period"
but when it matches "Period ID"
it returns Sequence[]
. I want it to return "Period"
in both cases.
{"Period ID","ID","Period"}/.$rule
{"ID", "Period"}
Within the $rule
I don't want to duplicate the string. For example, the following $rule
would work:
$rule={"Period ID"|"Period"->"Period"};
and returns the desired:
{"Period", "ID", "Period"}
But the $rule
has "Period"
appearing twice. How can I do this using RuleDelayed
?
With[{str = "Period"}, $rule = {"Period ID" | str -> str}]
? $\endgroup$