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
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Jun 24, 2010 1:35 pm   

%regex
 
Is it impossible to use variables inside of %regex?

The following: %regex(%trigger, "Your (?:@_test1) (?:@_test2)(?:s) ([\w '-,]+)", @_target)
or: %regex(%trigger, "Your (?:"@_test1") (?:"@_test2")(?:s) ([\w '-,]+)", @_target)


doesn't match:
Your slash maims a minotaur spectator

even when @_test1=slash and @_test2=maim

However, if I take that pattern out, put it in a trigger and mark it as regex, it suddenly works just fine.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Jun 24, 2010 4:40 pm   
 
First, Variables are *never* expanded within " quotes. In your second example, you are trying to use implicit concat, which is not reliable. The correct way to do this is:
Code:
%regex(%trigger, %concat("Your (?:",@_test1,") (?:",@_test2,")(?:s) ([\w '-,]+)"), @_target)

with the explicit call to %concat.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Jun 24, 2010 5:17 pm   
 
Thanks, Zugg. I need to use %concat() more often than I do, most likely.

Edit: Hmm, interestingly enough, that exact concat didn't match either. Label me confused.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Zugg
MASTER


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

PostPosted: Thu Jun 24, 2010 5:39 pm   
 
Something else is wrong then. Try assigning the %concat to a variable and then use the variable in the %regex call and print the variable out for debugging to be sure it is constructing the pattern correctly.
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Jun 24, 2010 6:25 pm   
 
I've never really used the debug window much, but it wasn't showing the values of the local variables to me, even with every message turned on except ansi codes.

However, I did try:

$_pattern=%concat("Your (?:", %1, ") (?:does )?(?:", %replace(%2, "*", "\*"), ")(?: things to)? ([\w '-,]+)")
%regex(%trigger, $_pattern, $target)

And that worked just fine. Which works enough for this trigger, but I'm still quite confused why it won't work with variables, I can play with that later I suppose.
_________________
Listen to my Guitar - If you like it, listen to more
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