• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

String replace '[' or ']' how? (1 Viewer)

DarkHack

Newcomer
Joined
Dec 14, 2021
Messages
3
Reaction score
0
Hi,
I search to use some path with '[' and ']', but in unix maybe windows too,
for mkdir path, like
#find \[dw\]/\[core\]/
[dw]/[core]/
[dw]/[core]/dwInit
[dw]/[core]/dwInit/client
I have to escape the '[' by '\', so with gsub,
I had tried :
path:gsub(string.format("%c", 91),string.format("%c%c", 92,91))
return :
malformed pattern (missing ']')
 

DarkHack

Newcomer
Joined
Dec 14, 2021
Messages
3
Reaction score
0
I had tried :
path:gsub("\[","\\\[")

invalid escape sequence near '"\['
 

DarkHack

Newcomer
Joined
Dec 14, 2021
Messages
3
Reaction score
0
Yes, found, sorry, juste I learn basics.

path=path:gsub('%[','\\['):gsub('%]','\\]')
 
Top