0

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

Yu Hao
  • 119,891
  • 44
  • 235
  • 294

1 Answers1

1
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.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • what about: `local s1,s2 = str:match'(.+)%s+has gathered%s+(.+)%s+from'`? would be faster I think – nonchip Jun 27 '14 at 14:40