|
harley Apprentice
Joined: 05 Apr 2008 Posts: 121
|
Posted: 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.. |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: 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 |
|
|
|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: 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. |
|
|
|
harley Apprentice
Joined: 05 Apr 2008 Posts: 121
|
Posted: Thu Oct 28, 2010 11:19 am |
Perfect!
Would it be easier to keep the string within the trigger or create a seperate stringlist? |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: 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 |
|
|
|
|
|