Jump to content

string.gsub


Karoffe

Recommended Posts

Posted

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

Posted

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 ?

  • MTA Team
Posted

`-` (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)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...