Fathoni267 Posted April 10 Share Posted April 10 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 1 Link to comment Share on other sites More sharing options...
0 CmP Posted April 10 Share Posted April 10 (edited) 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; ... Edited April 10 by CmP 2 Link to comment Share on other sites More sharing options...
Question
Fathoni267
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
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now