从字符串中提取最后一部分

发布于 2025-01-13 06:05:22 字数 133 浏览 3 评论 0原文

我有一个字符串,如下所示:

local string = 'VALUE1_VALUE2_VALUE3_VALUE4'

我想仅使用 string.match 获取 VALUE4。我该怎么做?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-01-20 06:05:22

这会匹配字符串末尾的 VALUE4

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

对于更通用的解决方案,您可以执行以下操作:

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

匹配字符串末尾的字母数字字符序列。

目前尚不清楚您实际上想做什么。但这应该给你一个起点。请参考Lua手册。

This matches VALUE4 at the end of a string

print(str:match("VALUE4
quot;))

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

print(str:match("%w+
quot;))

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文