I want to simply match a string in which only one or two numbers might change. Examples:
Cutoff 1
Cutoff 2
...
Frequency 1 (EQ 1)
Frequency 2 (EQ 2)
...
Now I am trying to use string.match(), and finding some good documentation, but I only can find stupid dissertations about lua string matching, not giving any real life examples.
I tried this:
Frequency [%d+] (EQ [%d+])
Frequency %d+ (EQ %d+)
Both tries for a proper matching string do not work, of course. Any idea here, please? Questions:
How do I match an exact string part, like "Frequency " (including the whitespace)?
Do I need to interpolate the bracket signs?
Omg, I simply wanted to use a simple pattern matching, but it turns out that LUA devs expect me to spend my whole weekend for such stupid things…
String stuff gets annoying. I’ve been gradually accumulating helper functions in a library I use in most of my tools to do stuff like splitting on spaces, certain matches, turning a comma-delimited string into a table, etc.
Yeah my description is lame. Let me try again. I have a variable startString, containing for example “!!”. Now I want to match some string, if my startString is at the beginning of that string.
I tried your suggested pattern. But somehow it doesn’t match.
Do you have an exact code example? Both of your examples should work, but it depends what value startString has.
myString = "my little test works!"
startString = "my little "
if string.match(myString, "^" .. startString .. ".*") then
print ("match")
else
print ("no match")
end
It’s important that startString should be escaped, when the value has magic characters.
Damn! Guys, @4tey@toimp so sorry for wasting your time! The string I wanted to match simply was the wrong one, I looked for “device.name”, which never changes, instead “device.display_name”… LOL