I am trying to understand what is the difference between string.find and string.match in Lua. It seems to me that both find the pattern in a string. But what is the difference? And how can I use them each? Say, if I had the string "Disk Space: 3000 kB" and I wanted to extract "3000" from it.
EDIT: Well, I think I did too much and now I'm lost. Basically, I need to translate this from Perl to Lua:
my $mem;
my $memfree;
open(FILE, 'proc/meminfo');
while (<FILE>)
{
if (m/MemTotal/)
{
$mem = $_;
$mem =~ s/.*:(.*)/$1/;
}
elseif (m/MemFree/)
{
$memfree = $_;
$memfree =~ s/.*:(.*)/$1/;
}
}
close(FILE);
So far I have written this:
for Line in io.lines("/proc/meminfo") do
if Line:find("MemTotal") then
Mem = Line
Mem = string.gsub(Mem, ".*", ".*", 1)
end
end
But this is obviously wrong. What will I not get? I understand why this is wrong, and what it actually does, and why, when I do
print(Mem)
he returns
.*
but I donβt understand how to do it right. Regular expressions confuse me!