This is regarding PCRE regular expression matching and has to do with an incorrect result being assigned to the matching %<> that is passed along to a script; Lua in my case.
Regex:
Trigger:
Test:
Result:
The expected result is for "thing" to be "a rock" for both poking and prodding.
The problem is that the value assigned to %<thing> is always the last group which may not have a value for the named group as it wasn't a match. This can be demonstrated by swapping the order of the logical expression:
I can confirm that the PCRE library which MUSH uses does handle this expression correctly:
Result:
This is most likely due to an error in handling the result from the match when Mush assigns values to its special %<> variables.
Regex:
(?J)^(You poke (?P<thing>.+)|You prod (?P<thing>.+))$Trigger:
<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="(?J)^(You poke (?P<thing>.+)|You prod (?P<thing>.+))$"
regexp="y"
send_to="12"
>
<send>
print("Thing -- " .. "%<thing>")
</send>
</trigger>
</triggers>Test:
You poke a rock
You prod a rockResult:
You poke a rock
Thing --
You prod a rock
Thing -- a rockThe expected result is for "thing" to be "a rock" for both poking and prodding.
The problem is that the value assigned to %<thing> is always the last group which may not have a value for the named group as it wasn't a match. This can be demonstrated by swapping the order of the logical expression:
(?J)^(You prod (?P<thing>.+)|You poke (?P<thing>.+))$I can confirm that the PCRE library which MUSH uses does handle this expression correctly:
Regex = "(?J)^(You poke (?P<thing>.+)|You prod (?P<thing>.+))$"
Regex = rex.new(Regex)
_, _, Table = Regex:match("You poke a rock")
print(Table[2])
print(Table[3])
print()
Regex = "(?J)^(You prod (?P<thing>.+)|You poke (?P<thing>.+))$"
Regex = rex.new(Regex)
_, _, Table = Regex:match("You poke a rock")
print(Table[2])
print(Table[3])Result:
a rock
false
false
a rockThis is most likely due to an error in handling the result from the match when Mush assigns values to its special %<> variables.