Gammon Forum
Entire forum
MUSHclient
Lua
Scripting a regular expression creation
Scripting a regular expression creation
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Shaun Biggs
USA (644 posts) bio
|
Date
| Sun 27 May 2007 04:55 PM (UTC) |
Message
| I'm trying to make an alias to set the prompt and create a trigger which matches on the prompt for Aardwolf. The only difficulty I'm having is with colour codes. Aard uses the @ symbol to denote a colour. The @ and any single character after it is eaten by the parser, except for @~- which are special characters. "@@" = "@", "@~" or "@-" = "~".
I have the following:
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
> s="@CC@cc@@@~@C@@@-asdf"
> for w in string.gmatch(s, "(@.)") do
>> if w == "@@" then
>> print("@")
>> elseif w == "@-" or w == "@~" then
>> print("~")
>> end
>> end
@
~
@
~
>
But I would like to have a string where I'm adding the unmatched sections to the modified ones I'm printing. The example string would wind up being "Cc@~@~asdf". For some really strange reason, I'm having a hard time getting my brain around the last step of this :( |
It is much easier to fight for one's ideals than to live up to them. | top |
|
Posted by
| Ked
Russia (524 posts) bio
|
Date
| Reply #1 on Sun 27 May 2007 05:39 PM (UTC) |
Message
| It looks like a job for string.gsub(). This produces the needed result:
function fixString(st)
return string.gsub(st, "(@.)",
function (m)
local t = {["@@"] = "@", ["@-"] = "~", ["@~"] = "~"}
return t[m] or ""
end )
| top |
|
Posted by
| Shaun Biggs
USA (644 posts) bio
|
Date
| Reply #2 on Sun 27 May 2007 05:53 PM (UTC) |
Message
| That works perfectly. Thank you very much. |
It is much easier to fight for one's ideals than to live up to them. | top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
12,138 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.