I'm pretty sure this involves string patterns, but I'm finding a way to get a group of characters in between two defined strings. For example,
string = "apple orange banana watermelon"
The two defined strings could be "apple"
and "banana"
, so the text in between is " orange "
, and that's what it would print.
Is there something like that I can do? Thanks.
-SkeletalReality
local s = "apple orange banana watermelon" print(string.match(s, "apple(.*)banana")) -- prints " orange "
The pattern string, "apple(.*)banana"
captures any string (.*)
between apple
and banana
. string.match
will then return this capture.