0

If I have a string like this.

local string = "D:/Test/Stuff/Server/resources/[Test]/SuperTest"

How would I remove everything after the word "server" so it will end up look like this

local string = "D:/Test/Stuff/Server"
TylerH
  • 20,799
  • 66
  • 75
  • 101
Birk
  • 191
  • 2
  • 12
  • 2
    Basically, [here it is](https://stackoverflow.com/questions/50396678/lua-match-everything-after-character-in-string). – Wiktor Stribiżew Mar 31 '21 at 19:51
  • 2
    `print(("D:/Test/Shit/Server/resources/[Test]/SuperTest"):match("(.*Server)"))` – Nifim Mar 31 '21 at 20:26
  • 1
    And ```do local string=("D:/Test/Shit/Server/resources/[Test]/SuperTest"):match("(.*Server)"):gsub('/','\\') print(string) end``` corrects it to backslashes ;-) – koyaanisqatsi Mar 31 '21 at 22:46

1 Answers1

0

use str instead of string to not shadow the real string library

local str = "D:/Test/Stuff/Server/resources/[Test]/SuperTest"

here a solution

str = str:match("(.*Server)")

or use do...end to avoid shadowing

do
    local string = ("D:/Test/Stuff/Server/resources/[Test]/SuperTest"):match("(.*Server)")
end
Mead
  • 100
  • 10