|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed May 14, 2008 1:43 pm
[2.25] Trigger captures within stringlists |
I was experimenting to see whether a trigger can use a stringlist which contains captures. I got an unexpected result:
Code: |
#var testlist {This is a (test)|This is a (quiz)}
#trig {{@testlist}} {#show succeed: %1}
#say this is a test
#say this is a quiz
|
The results were:
Quote: |
this is a test
succeed: test
this is a quiz
succeed:
|
The trigger works fine, and produces the Succeed output, but the capture only works on the first string value. I'm not sure whether it can be considered a bug, since I wasn't sure it would work at all. But it is curious that it works partially but not completely. |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Wed May 14, 2008 2:01 pm |
Shouldn't you be doing
for this is a quiz?
|
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed May 14, 2008 2:28 pm |
That would not be what I would expect. I expect the trigger to test the string "This is a (test)" and when that fails test "This is a (quiz)", thus "quiz" is the first parameter in that tested string. But I can somewhat see your logic. So, here is another test:
Code: |
#var testlist {This is a (test)|This is a (quiz)|This is an (experiment)}
#trig {{@testlist}} {#show Success-- 1:%1 2:%2 3:%3}
#show @testlist
#show This is a test
#show This is a quiz
#show This is an experiment
|
Which gives this result:
Quote: |
This is a (test)|This is a (quiz)|This is an (experiment)
This is a test
Success-- 1: 2:test 3:
This is a quiz
Success-- 1: 2: 3:quiz
This is an experiment
Success-- 1:experiment 2: 3:
|
So, it is capturing in this test, but the parameter number doesn't match the index of each phrase in the stringlist. Very odd!
Edit: I have figured out why it is not in the order I expected. The trigger is sorting the list alphabetically for the regex. |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Wed May 14, 2008 2:45 pm |
This is interesting and a very good thing to know for anyone who might try this method of capturing things in a trigger pattern. To keep it aligned, you're best off keeping your string list sorted in advance. Avoid surprises that way.
|
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Wed May 14, 2008 3:01 pm |
Yeah stringlist are sorted in alphabetically in reverse order, without that if for a given entry there was another entry that came before it that was a prefix,
the prefix would match, the full string would never match.
Rahab wrote: |
That would not be what I would expect. I expect the trigger to test the string "This is a (test)" and when that fails test "This is a (quiz)", thus "quiz" is the first parameter in that tested string. |
That's just how regular expressions work the capturing group is numbered according to it's appearance in the entire PATTERN from left to right. |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed May 14, 2008 3:16 pm |
Yeah, I can see the logic now. I was thinking local, but the regex has to look globally. Makes it tricky to use this method, but it could still be useful. I'll have to keep it in mind.
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed May 14, 2008 4:34 pm |
If you're sure you'll always get only one result, you could do something like %concat(%1,%2,%3) and always get only that one result.
|
|
|
|
|
|