Jamifi
Jamifi

Reputation: 1

Extract last part from string

I have a string, which looks like this:

local string = 'VALUE1_VALUE2_VALUE3_VALUE4'

I would like to get the VALUE4 only using string.match. How can i do this?

Upvotes: 0

Views: 1223

Answers (1)

Piglet
Piglet

Reputation: 28994

This matches VALUE4 at the end of a string

print(str:match("VALUE4$"))

For a more general solution you can do something like this:

print(str:match("%w+$"))

Match a sequence of alphanumeric characters at the end of your string.

It is not clear what you are actually trying to do. But this should give you a starting point. Please refer to the Lua manual.

Upvotes: 2

Related Questions