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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Zhiroc
Adept


Joined: 04 Feb 2005
Posts: 246

PostPosted: Wed Apr 12, 2006 2:44 am   

Using a stringlist in %subregex
 
I can't seem to get a %subregex working where I have stringlist variable embedded in the regex:
Code:
#VAR tmp1 {aaa bbb ccc ddd}
#VAR tmp2 {bbb|ddd}
#show {1> @tmp1}
#show {2> @tmp2}
#show {3> %subregex( @tmp1, "(bbb|ddd)", "***")}
#show {4> %subregex( @tmp1, "(@tmp2)", "***")}
#show {5> %subregex( @tmp1, (@tmp2), "***")}
#show {6> %subregex( @tmp1, %expand( (@tmp2)), "***")}

gives
Code:
1> aaa bbb ccc ddd
2> bbb|ddd
3> aaa *** ccc ***
4> aaa bbb ccc ddd
5> aaa bbb ccc ddd
6> aaa bbb ccc ddd

Any ideas what I'm doing wrong?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Apr 12, 2006 5:28 am   
 
Try taking out the parentheses. While ZMud uses them to keep track of nested lists, I believe they get removed when referencing that element. Thus, "(bbb|ddd)" is exactly the same as "bbb|ddd".
_________________
EDIT: I didn't like my old signature
Reply with quote
Zhiroc
Adept


Joined: 04 Feb 2005
Posts: 246

PostPosted: Wed Apr 12, 2006 6:59 am   
 
Added:
Code:
#show {7> %subregex( @tmp1, "bbb|ddd", "***")}
#show {8> %subregex( @tmp1, @tmp2, "***")}

but still got:
Code:
7> aaa *** ccc ***
8> aaa bbb ccc ddd
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Wed Apr 12, 2006 2:12 pm   
 
This is a good example of the difference between expanding values with %expand and expanding them with <>. If you enable <> expansion in your preferences, you can then force the expansion in your function. (Actually, my test shows that you don't even have to enable the expansion for this to work. Is that a bug or an undocumented feature? ;) )

Code:
#show %subregex(@tmp1, "(<@tmp2>)", "***")
Reply with quote
Zhiroc
Adept


Joined: 04 Feb 2005
Posts: 246

PostPosted: Wed Apr 12, 2006 3:42 pm   
 
OK, yes that works. Perhaps the problem is that the string is "compiled" by the script, and not parsed by %subregex() at runtime? So, substitutions have to take place before this is done (which the <> does), but using functions happens "too late". Thus the following doesn't work, even though it produces the correct string:
Code:
#show {Aa> %concat( "(", %expand( @tmp2), ")")}
#show {A> %subregex( @tmp1, %concat( "(", %expand( @tmp2), ")"), "***")}
Code:
Aa> (bbb|ddd)
A> aaa bbb ccc ddd
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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