Hello.
I need to extract a part of a string (a number inside). I tried on lua:
print(string.gsub(“t-shirt:100”, “t-shirt:”,""))
t-100 1
As you can see I can’t remove string before “-”: is that a bug?
How to resolve?
Thanks
Hello.
I need to extract a part of a string (a number inside). I tried on lua:
print(string.gsub(“t-shirt:100”, “t-shirt:”,""))
t-100 1
As you can see I can’t remove string before “-”: is that a bug?
How to resolve?
Thanks
In a pattern match ‘-’ is a “magic” character. You need to escape it with ‘%’,
but that string is generated from an automatic software (i.e. photils) and I’m not have control on that.
Other solution to avoid that?
Thanks
You mean that photils creates the pattern you want to match, or the string where you look for that pattern?
In the example you give, I’d expect
print(string.gsub(“t-shirt:100”, “t%-shirt:”,""))
to do what you want
But I don’t know the string.
photils return a string tag (word:score) from which I’d like separate the word (i.e. “t-shirt”, or another one like “kid” or “pizza” or “blue-jeans”… ) and the score (to convert in number to compare).
The script works but when get that word go in error.
Thanks, it seems to work so!!
string.gsub(tag, ds.sanitize_lua(word)…":", “”)
You can also use string.match to find characters in a string.
match only numbers with this pattern:
print(string.match(‘t-shirt:100’, “%d+”))
result: 100