fork(19) download
  1. function repl(v)
  2. res, _ = string.gsub(v:gsub('|[()]$', ''), '|[()]', ' \\')
  3. return res
  4. end
  5.  
  6. print(repl('abcdef'))
  7. print(repl('abcd|('))
  8. print(repl('abcde|(foo'))
  9. print(repl('abcd|)'))
  10. print(repl('abcde|)foo'))
  11.  
  12. --if there is no | then do nothing
  13. --if nothing follows of the |( or |) then delete these two characters
  14. --if something follows then replace |( or |) with <space>\
Success #stdin #stdout 0s 14112KB
stdin
Standard input is empty
stdout
abcdef
abcd
abcde \foo
abcd
abcde \foo