Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
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.
13,481 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top