Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
TheHardCount
Newbie


Joined: 06 Aug 2007
Posts: 5
Location: Las Vegas, Nevada

PostPosted: 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?
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
TheHardCount
Newbie


Joined: 06 Aug 2007
Posts: 5
Location: Las Vegas, Nevada

PostPosted: Fri Oct 26, 2007 9:50 pm   
 
Thanks Zugg!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net