[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  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] Refresh page


Posted by Shaun Biggs   USA  (644 posts)  [Biography] 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.
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] 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 )
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] 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.
[Go to top] 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] Refresh page

Go to topic:           Search the forum


[Go to top] 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.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]