Reputation: 20212
Is it possible to find two specific words which are next to each other, with match
or gmatch
?
Example:
local usb_dfh = "Filesystem Size Used Available Use% Mounted on tmpfs"
Let's say you try to match "Mounted on". Is this possible?
Info:
My goal is to find "Mounted on"
and replace it with "Mounted_on"
.
Upvotes: 0
Views: 50
Reputation: 122383
As the name implies, string.match
and string.gmatch
are used to match. To replace, use string.gsub
:
usb_dfh:gsub('Mounted%s+on', 'Mounted_on')
%s+
matches one or more whitespace characters.
Upvotes: 3
Reputation: 20212
I found the solution for my problem.
usb_dfh = string.gsub(usb_dfh, "Mounted on", "Mounted_on")
But the question remains. Is it possible to match two specific words with gmatch?
Upvotes: 0