0

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?

Nifim
  • 4,758
  • 2
  • 12
  • 31
Jamifi
  • 1

1 Answers1

2

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.

Piglet
  • 27,501
  • 3
  • 20
  • 43