我有一个具有字符串值的表
data_table = {'(?P<smartcache>.+)$', 'css', '123454', '(?P<version>.+)$'}
我正在尝试查看字符串startswith
'(?P <'和endswith
')$'。我想要一个输出字符串,就像
output_table = '/smartcache/css/123454/version'
我在获取值时遇到问题,这些值是通过'smartcache'
要从中获取的模式传递的(?P<smartcache>.+)$
。
我的尝试:
out_string_value = (string.match(uri_regex, '[^(?P<].+[)$]')
在这里,我可以根据smartcache>.+)$
需要获取输出smartcache
。
local uri_regex = '(?P<smartcache>.+)$'
local out_string_value = uri_regex:match('^%(%?P<([^>]+)>.*%)%$$')
print(out_string_value)
Lua模式^%(%?P<([^>]+)>.*%)%$$
与正则表达式类似,不同之^\(\?P<([^>]+)>.*\)\$$
处在于Lua模式用于%
转义魔术字符。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句