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


Joined: 05 Apr 2008
Posts: 121

PostPosted: Thu Oct 28, 2010 3:02 am   

[3.31] %replace question
 
What i'd like to do is take a variable created via trigger:
QuestMob = A blue cat

What i'd like to do is strip off the common words in the variable, ie A/the etc.
I was thinking something like %replace(@questmob,a, "") but the problem is if 'a' is in multiple locations.. like in the above example.

Any idea how to just strip the words.. I could even create a stringlist of the words..
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Oct 28, 2010 4:10 am   
 
Use %subregex instead.

QuestMob=%subregex(@QuestMob,"(?:a|the|of)\b","")

Of course, you can add on to the string list within the (?:) bit. You will need to add capital versions of it as well, though (A|The|etc).

Charneus
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: Thu Oct 28, 2010 6:18 am   
 
The following pattern should take care of the case sensitivity:

"(?i)(?:a|the|of)\b"

Though I have the feeling that %subregex defaults to case-insensitive.

So in Charneus' example it would appear as this:
Code:

QuestMob = %subregex(@Questmob,"(?i)(?:a|the|of)\b","")

To force it to be case-sensitive use (?-i) instead of (?i).
_________________
Sic itur ad astra.
Reply with quote
harley
Apprentice


Joined: 05 Apr 2008
Posts: 121

PostPosted: Thu Oct 28, 2010 11:19 am   
 
Perfect!
Would it be easier to keep the string within the trigger or create a seperate stringlist?
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu Oct 28, 2010 2:41 pm   
 
I'd probably keep the string within the trigger.

By the way, make one small change... I had it this way before, but I guess I accidentally removed it...

Questmob = %subregex(@Questmob, "\b(?i)(?:a|the|of)\b","")

Otherwise, you'd wind up stripping things like "Car[b]the[\b] is sitting here."

Glad we could help, and thanks, Anaristos - I wasn't sure if CMUD did accept (?i) for insensitivity.

Charneus
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