I’m making a script that replaces string patterns with another string. I’ve got most things working but I need string.match to match just a dot (.) but not a dot with a percentage symbol in front of it(%.). I’ve tried many things but none of them have worked.
May you send your code so I can view it?
I’ve tried
string.match("[^%%]*.", replacement)
but that hasn’t worked
Can you show me what you are attempting to replace?
do you mean you want to replace periods?:
local String = string.gsub("Test.Hello","[\.]","Test")
print(String)
Would error at run-time. This would only work if it was Regex.
What do you mean?
local String = string.gsub("Test.Hello.New","[\.]","Test")
print(String)
Just tried running it on a Lua 5.1 compiler and errored, strange.
No I want to replace periods that have % in front of them
“%.” would get replaced but not “.”
local String = string.gsub("Test.Hello.New","[\\.]","Test")
print(String)
This works fine though.
local Pattern = "%%%."
local Pattern = "%%%."
local String = "%."
print(String)
String = String:gsub(Pattern, ".")
print(String)
Sorry I meant it the other way around; “%.” wouldn’t get replaced but “.” would
So you want to replace a “.” to “%.”?
No what “.” will be replaced with isn’t really relevant. I need “.” to be replaced and not “%.”
“.” can have any character in front of it except “%” to be replaced
So you just want periods to be replaced
local Pattern = "%."
local String = "Hey. How are you."
print(String)
String = String:gsub(Pattern, "Replacement")
print(String)
This kind of works but “%.” also gets replaced, when it shouldn’t.
Let me try cook something up real quick.
local string = "'.' | '%.'"
local pattern = "([^%%])%."
local replacement = "Hey"
print(string)
string = string:gsub(pattern, "%1" .. replacement)
print(string)