Lua は文字列内の指定された位置にある数値をインターセプトします
要件: 文字列内の指定されたデジタル情報を抽出します。
質問: description:gsub("%D+", "") は文字列のすべての桁を抽出します。
解決策: string.find() を使用して指定した場所の情報を抽出し、現在の情報の番号を抽出します。
デモ
local description = "这是一个带多个123456789数字的<color=#E45C6D>160</color>字符串"
local targetNum1 = description:gsub("%D+", "")
print("取出键值中的数字:"..targetNum1)
local targetKey = "(>%d+</color>)"
local _, _, gotKey = string.find(description, targetKey)
print("取出键值:"..gotKey )
local targetNum2 = gotKey:gsub("%D+", "")
print("取出键值中的数字:"..targetNum2)
出力
取出键值中的数字:123456789456160
取出键值:>160</color>
取出键值中的数字:160