Lua string.gsub具有多个模式 [英] Lua string.gsub with Multiple Patterns
问题描述
我正在重命名包含多余字母的电影标题. string.gsub
可以将字符串替换为" nil值,但是我大约有200种字符串模式需要替换为".
I am working on renaming the Movie titles that has unwanted letters. The string.gsub
can replace a string with "" nil value but I have around 200 string patterns that need to be replaces with "".
现在,对于每个模式,我都必须string.gsub
.我当时在想是否有一种方法可以将所有字符串模式都放在单个string.gsub
行中.我已经在网上搜索了解决方案,但仍然什么也没得到.
Right now I have to string.gsub
for every pattern. I was thinking is there is a way to put all the string patterns in to single string.gsub
line. I have searched around the web for the solution but still didn't got anything.
电影标题就是这样B.A.Pass 2013 Hindi 720p DvDRip CROPPED AAC x264 RickyKT
我想删除多余的字符,例如2013
,Hindi
,720p
,DvDRip
,CROPPED
,AAC
,x264
,RickyKT
.
The movie title is like this B.A.Pass 2013 Hindi 720p DvDRip CROPPED AAC x264 RickyKT
and I want to remove the extra characters like 2013
, Hindi
, 720p
, DvDRip
, CROPPED
, AAC
, x264
, RickyKT
.
推荐答案
您可以将表作为第三个参数传递给string.gsub
,如下所示:
You can pass to string.gsub
a table as the third argument like this:
local movie = "B.A.Pass 2013 Hindi 720p DvDRip CROPPED AAC x264 RickyKT"
movie = movie:gsub("%S+", {["2013"] = "", ["Hindi"] = "", ["720p"] = "",
["DvDRip"] = "", ["CROPPED"] = "", ["AAC"] = "",
["x264"] = "", ["RickyKT"] = ""})
print(movie)
这篇关于Lua string.gsub具有多个模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!