FangYX Posted April 10, 2022 Share Posted April 10, 2022 How to get only up to the second str? (I want the output is "str a str") Quote text="str a str bc str cde str" print(string.match(text, "str.*str")) if like that the output always show the last str Link to comment Share on other sites More sharing options...
CmP Posted April 10, 2022 Share Posted April 10, 2022 Use "-" quantifier instead of "*": string.match(text, "str.-str") From Lua reference manual (https://www.lua.org/manual/5.3/manual.html#6.4.1) : Quote A pattern item can be ... a single character class followed by '-', which also matches zero or more repetitions of characters in the class. Unlike '*', these repetition items will always match the shortest possible sequence; ... Link to comment Share on other sites More sharing options...
Question
FangYX
How to get only up to the second str?
(I want the output is "str a str")
if like that the output always show the last str
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.