Karoffe Posted October 23, 2014 Share Posted October 23, 2014 Just a quick question, what if i got a string like this "Word(12)", How to transform it to be : "12", so i actually want to remove "Word()". EDIT: In a better way i want someone to explain me how the patterns work Link to comment
MTA Team botder Posted October 23, 2014 MTA Team Share Posted October 23, 2014 local text = "Word(12)" local extracted = text:match(".-%((%d+)%)") http://www.lua.org/pil/20.2.html Link to comment
Karoffe Posted October 23, 2014 Author Share Posted October 23, 2014 Thanks, Working. but i've got some questions, local text = "Word(12)"local extracted = text:match(".-%((%d+)%)") What is the utility of the colored characters in there ? Link to comment
MTA Team botder Posted October 23, 2014 MTA Team Share Posted October 23, 2014 `-` (not greedy) and `+` (greedy) tell the expression to accept 0/1 or more characters, which match `.` (every character). You have to use the not-greedy operator, because it could "eat" the characters beyond the `(` too. Edit: `-` matches 0 or more characters (matches the shortest sequence - not greedy), `+` matches 1 or more characters (matches the longest sequence - greedy) Link to comment
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