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


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

Lua code

function parse(pattern)
  pattern = pattern
    :gsub("<quoted>", "([^\"]*)")
    :gsub("<quoted2>", "([^\"]*)")
    :gsub("<rest>", "(.*)")
  return input:match("^"..pattern.."$")

if input == "" then return "" end

cmdpattern = 'replace "<quoted>" with "<quoted2>" in this text: <rest>'
pattern, replacement, text = parse(cmdpattern)
if pattern then
  return text:gsub(pattern, replacement) -- simplest solution - no escaping for now
  return("Error. Syntax: "..cmdpattern) -- for now return instead of error because error doesn't seem to work that great yet

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: 875 / 296
Referenced in: [show references]