Reputation: 3
Is there a way to split string like:
"importanttext1 has gathered importanttext2 from stackoverflow."
I want to grab anything before the word "has"
, and just want to grab the one word after "gathered"
, so it doesn't include "from stackoverflow."
. I want to be left with 2 variables that cointain importanttext1
and importanttext2
Upvotes: 0
Views: 272
Reputation: 122493
local str = "importanttext1 has gathered importanttext2 from stackoverflow."
local s1 = str:match("(.+)has")
local s2 = str:match("gathered%s+(%S+)")
print(s1)
print(s2)
Note that "%s"
matches a whitespace character while "%S"
matches a non-whitespace character.
Upvotes: 1