Hello,
str = "workspace.IdealistDeveloper" specialized_str_pattern; -- Not sure what this would be yet. for i in string.gmatch(str, specialized_str_pattern) do print(i) end
workspace
IdealistDeveloper
str = "workspace.CrayMonkey1212_.Head" specialized_str_pattern; -- Not sure what this would be yet. for i in string.gmatch(str, specialized_str_pattern) do print(i) end
workspace
CrayMonkey1212_
Head
Best regards,
IdealistDeveloper
The answer here is a fairly simple one, and there are really two ways of doing this ,dependent on what you plan on doing. If the code you have has no special characters besides the period, you can do [^%p]+
which gets non punctuation characters in a given string. However, if there are special characters , you would have to use [^%.]+
, which gets non-period characters.
[^%.]+
is a special case as the period is a string pattern all to itself, being the pattern for all characters. To cancel out this characteristic, we can use the % character before it.
To shorten the code a bit, we can use the method version of the functions of the string library. Doing so is simply to shorten and make the code more simplfied, as
str:gmatch(pattern)
essentially functions the exact same as
string.gmatch(str,patter)
with that said, here is the product:
Case 1: ([^%.]+
can also be used here)
local str = "workspace.IdealistDeveloper" local specialized_str_pattern = "[^%p]+" for i in str:gmatch(specialized_str_pattern) do print(i)--workspace, IdealistDeveloper end
Case 2:
local str = "workspace.CrayMonkey1212_.Head" local specialized_str_pattern = "[^%.]+" for i in str:gmatch(specialized_str_pattern) do print(i)--workspace , CrayMonkey1213_, Head end
Another thing I would like to say is that the use of local variables is preferred for variables only used in its scope, and not a higher one, including the global scope.
This explanations was really skimming the surface here, to look at a more in depth and general explanation, go to the link below.
string patterns and "magic characters"
Hopefully this helped!