 |
Vorax Apprentice

Joined: 29 Jun 2001 Posts: 198 Location: USA
|
Posted: 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? |
|
|
 |
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: 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. |
|
|
 |
Vorax Apprentice

Joined: 29 Jun 2001 Posts: 198 Location: USA
|
Posted: Fri Jan 28, 2005 7:09 pm |
Hey, that worked!
Thanks! :) |
|
|
 |
Vorax Apprentice

Joined: 29 Jun 2001 Posts: 198 Location: USA
|
Posted: 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? |
|
|
 |
Vorax Apprentice

Joined: 29 Jun 2001 Posts: 198 Location: USA
|
Posted: Fri Jan 28, 2005 7:49 pm |
Actually, nevermind. I figured out the problem: using . instead of \ to quote the colon.
|
|
|
 |
|
|