Is there any way to replace '-' with string.gsub

Title says it all really,

Is there any way for me to replace the ‘-’ character with string.gsub since I believe its a special character but I really need a way to replace it.

My specific use case is replacing ‘–’ however this also appears to trigger the special use case.

1 Like

You can use %- (or \- if you’re on RegEx) for literal -.

print(("abz - eample"):gsub("[a%-z]", "X")) --> XbX X eXmple
1 Like

Just to more specifically solve my issue, how would this work if I wanted to only sub if it were two connecting dashes, tried some common sense solutions yet couldn’t yield a valid result.

The same way you would do it for any other character:

str:gsub("%-%-", ...)

3 Likes