Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

17
LINES

< > BotCompany Repo | #36 // Replace command handler

Lua code

1  
function parse(pattern)
2  
  pattern = pattern
3  
    :gsub("<quoted>", "([^\"]*)")
4  
    :gsub("<quoted2>", "([^\"]*)")
5  
    :gsub("<rest>", "(.*)")
6  
  return input:match("^"..pattern.."$")
7  
end
8  
9  
if input == "" then return "" end
10  
11  
cmdpattern = 'replace "<quoted>" with "<quoted2>" in this text: <rest>'
12  
pattern, replacement, text = parse(cmdpattern)
13  
if pattern then
14  
  return text:gsub(pattern, replacement) -- simplest solution - no escaping for now
15  
else
16  
  return("Error. Syntax: "..cmdpattern) -- for now return instead of error because error doesn't seem to work that great yet
17  
end

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Image recognition results

Recognizer Recognition Result Visualize Recalc
#308 589 [visualize]

Snippet ID: #36
Snippet name: Replace command handler
Eternal ID of this version: #36/1
Text MD5: 207674a9cd9cc1a82c997edeaefb02a8
Author: stefan
Category: tools
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2013-12-14 00:41:54
Source code size: 589 bytes / 17 lines
Pitched / IR pitched: Yes / Yes
Views / Downloads: 1030 / 338
Referenced in: [show references]