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


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Wed Aug 18, 2004 10:21 pm   

Replacing text inside a variable
 
Morning folks.

I'm stuck on a variable replacing thing I've been workin on for a couple hours now, and I was hoping I could get some pointers.

The MUD I play has a guild that can acquire a catalog for listing equipment pieces. The catalog has a limit on space, so I'm using triggers to store all of the information on an item in a text file, and aliases to recall that info to the MUD window.

The variable looks essentially like this:

[cerimonial headdress of lloth] Cerimonial Headdress of Lloth
[cerimonial headdress of lloth] It increases user's constitution pitifully.
[cerimonial headdress of lloth] It increases user's intelligence pitifully.
[cerimonial headdress of lloth] It increases user's spellpoint regeneration pitifully.
[cerimonial headdress of lloth] It has non-existent armour class for its type (non-existent in general).
[cerimonial headdress of lloth] This item loses its magical powers with average speed.
[cerimonial headdress of lloth] It shines with brilliant red glow.
[cerimonial headdress of lloth] It emits darkness.
[cerimonial headdress of lloth] It modifies the user's ability to regenerate spell points.

As you can see, some item names are pretty lengthy, but I'm using the name in the [] brackets for searching purposes. Buuut, once it's found, I no longer need the full name in brackets, so I'm trying to strip all of the text in the [] brackets and replace it with something simpler, like:

[eqcatalog] Cerimonial Headdress of Lloth
[eqcatalog] It increases user's constitution pitifully.
[eqcatalog] It increases user's intelligence pitifully.
[eqcatalog] It increases user's spellpoint regeneration pitifully.
[eqcatalog] It has non-existent armour class for its type (non-existent in general).
[eqcatalog] This item loses its magical powers with average speed.
[eqcatalog] It shines with brilliant red glow.
[eqcatalog] It emits darkness.
[eqcatalog] It modifies the user's ability to regenerate spell points.


This is what I've come up with so far:

#var catsearch_matches %subchar( @catsearch_matches, "[%-1]", "[eqcatalog] ")

I've tried %subchar and %replace, without any real luck. It works just fine, so long as the alias argument is verbatim of the text to be removed, but I haven't been able to figure out a way to make the ~[*~] part allow pattern matching.

Ex- 'catalogsearch cerimonial headdress of lloth' with "[%-1]" has the result I want.
But 'catalogsearch lloth' with ~[*~] doesn't alter the text in []'s.


Sorry for the babbling, just hoping I can get a nod in the right direction.

Thank you for your time.
_________________
Fat Tony
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Aug 19, 2004 9:31 am   
 
Try using %subregex. It works based on regex pattern matching. You can use the trigger conversion to help you develop the regex pattern if your not familiar with regex.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
fattony
Apprentice


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Thu Aug 19, 2004 12:53 pm   
 
I've been working with the regex commands, and I can get the pattern matching down for simpler patterns, but anything more complicated than a single word won't seem to match up.

Is there a wildcard regex pattern that I'm not seeing..? I see the range things, but even that doesn't seem to match a varying number of words/spaces.

I've tried every variation I can think of, like

[[a-z\s]]
[\w\s]
[[a-z]\s]

etc etc etc, to fit in the

#var catsearch_matches %subregex( @catsearch_matches, [[a-z\s]], "[eqcatalog]")

line, but I can't get a regex pattern that will match a varying line of words or spaces. It's all lowercase, but some are [one two three] words or [one two] or [a whole bunch of words].

Is there a wildcard, similar to * for zMUD, that I'm missing..?
_________________
Fat Tony
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Thu Aug 19, 2004 3:47 pm   
 
In Regular Perl Expressions, the * isn't a wildcard, but says that the previous class (e.g. lower-case letters, [a-z]) may appear 0 or more times in a row.

A great resource for learning and understanding Regular Perl Expressions can be found at http://www.regular-expressions.info/reference.html
_________________
.geniusclown
Reply with quote
fattony
Apprentice


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Thu Aug 19, 2004 4:08 pm   
 
I know that * isn't the wildcard for Perl. What I'm asking is IS there a wildcard for Perl. I've read all of the helpfiles I can find, including the one you linked to, and have yet to find a solution that would match ANYthing, including letters, numbers, special characters, AND white space.

Ex- This is essentially what I want to do: "[[a-z?\s?]]"
This should match [word word], or [word word word], or [word], etc etc etc.
_________________
Fat Tony
Reply with quote
fattony
Apprentice


Joined: 27 Dec 2001
Posts: 105
Location: USA

PostPosted: Thu Aug 19, 2004 4:38 pm   
 
Perl/regex doesn't seem to have what it is I'm looking for. Is there a way to work around zMUD, so that I can force %replace to allow pattern-matching?

Something like:

#var catsearch_matches %replace( @catsearch_matches, %expand( ~[*~], -2), "[eqcatalog]")

or similar?
_________________
Fat Tony
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Thu Aug 19, 2004 5:35 pm   
 
Because your match of "[[a-z?\s?]]" doesn't include a *, all it will look for is a single character that is either a lower-case letter or a space in between the [].

Try using "[(.*)]". The . will match any non-linefeed character (including letters, numbers, and spaces), and the * allows it to be matched multiple times. The addition of () makes it so the matched bit can be access by %1.

So, your trigger would look like this:
Quote:
#REGEX {[(.*)]} {#PSUB {eqcatalog} %x1}


You can, of course, include some #IF statements if you want to use strings other than "eqcatalog".
_________________
.geniusclown
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