有没有办法分割字符串,如:
"importanttext1 has gathered importanttext2 from stackoverflow."
我想在单词"has"
之前抓取任何内容,只想在"gathered"
之后抓取一个单词,因此它不包含"from stackoverflow."
。我希望留下2个汇总importanttext1
和importanttext2
答案 0 :(得分: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)
请注意,"%s"
匹配空白字符,而"%S"
匹配非空白字符。