|
TheHardCount Newbie
Joined: 06 Aug 2007 Posts: 5 Location: Las Vegas, Nevada
|
Posted: Thu Oct 25, 2007 11:11 pm
%subregex pattern variables |
Hello,
This example from the help files no longer works:
Code: |
#SHOW %subregex("100 gold, 200 silver", "(\d+)", "%eval(%1+10)")
displays: 110 gold, 210 silver |
Entering it on the command line yields "10 gold, 10 silver" - the regular expression match is not being stored to the %1 variable.
How can I achieve the proper result in CMUD? |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Oct 26, 2007 5:09 pm |
I'll update the documentation.
In CMUD, to retrieve the matched subpattern within %subregex (or when using the #IF =~ or LIKE operators), you need to use the %pat function instead of %1. So instead of %1 you need %pat(1). So the example should read:
Code: |
#SHOW %subregex("100 gold, 200 silver", "(\d+)", "%eval(%pat(1)+10)") |
This is because %1..%99 are "compile-time" variables, whereas the %subregex is evaluating the 3rd argument dynamically at runtime. And %pat is the runtime function that returns subpatterns. |
|
|
|
TheHardCount Newbie
Joined: 06 Aug 2007 Posts: 5 Location: Las Vegas, Nevada
|
Posted: Fri Oct 26, 2007 9:50 pm |
Thanks Zugg!
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|