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
Vorax
Apprentice


Joined: 29 Jun 2001
Posts: 198
Location: USA

PostPosted: Fri Jan 28, 2005 6:41 pm   

Stringlists & %subregex ... how do I...?
 
I have several stringlist variables that contain info in this kind of format:
Code:
#VAR OnlineMortals {10online|0good|3evil|7neutral|0unaligned}

Where there is a number preceeding a word. I've been trying to use %subregex to reformat the strings to add a space between the number and the word but it never comes out right. The number is always missing.
I've tried this:
Code:
#FORALL @OnlineMortals {#SHOW %subregex("%i", "(\d+)", "%1 ")}

But that produces this:
Code:
 online
 good
 evil
 neutral
 unaligned

What am I doing wrong?
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Fri Jan 28, 2005 6:57 pm   
 
Try this:
#FORALL @OnlineMortals {#SHOW %subregex( "%i", "(\d+)", "%%1 ")}

The %%1 is needed because what zMUD does is to replace all %1 variables when the alias/trigger is executed. So %%1 delays the expansion.
Reply with quote
Vorax
Apprentice


Joined: 29 Jun 2001
Posts: 198
Location: USA

PostPosted: Fri Jan 28, 2005 7:09 pm   
 
Hey, that worked!

Thanks! :)
Reply with quote
Vorax
Apprentice


Joined: 29 Jun 2001
Posts: 198
Location: USA

PostPosted: Fri Jan 28, 2005 7:35 pm   
 
Ok, I've run into another problem...
Code:
#VARIABLE OnlineLevels {Levels6-10:1|Levels21-25:2|Levels26-30:3|Levels31-35:1|Levels41-45:1|Levels46-50:4}
#FORALL @OnlineLevels {#SHOW %subregex( "%i", "(Levels)(\d+.-\d+).:(\d+)", "%%1 %%2: %%3")}

Yields these results
Code:
Levels6-10:1
Levels 21-2: 2
Levels 26-3: 3
Levels 31-3: 1
Levels 41-4: 1
Levels 46-5: 4

The first line doesn't get formatted at all. The rest of the lines are missing the second digit after the hyphen. What's wrong this time?
Reply with quote
Vorax
Apprentice


Joined: 29 Jun 2001
Posts: 198
Location: USA

PostPosted: Fri Jan 28, 2005 7:49 pm   
 
Actually, nevermind. I figured out the problem: using . instead of \ to quote the colon.
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