Php 使用Lua表结构解析字符串
我有一个具有这种结构的字符串(它是Lua Table) 为了便于阅读:Php 使用Lua表结构解析字符串,php,regex,parsing,Php,Regex,Parsing,我有一个具有这种结构的字符串(它是Lua Table) 为了便于阅读: {['Name1']={score=235,x=6,y=88}, ['Name2']={score=112,x=12,y=55}, ['Name3']={score=15,x=15,y=56},} <--there might be more entries than these three of course {['Name1']={score=235,x=6,y=88}, ['Name2']={score=112
{['Name1']={score=235,x=6,y=88},
['Name2']={score=112,x=12,y=55},
['Name3']={score=15,x=15,y=56},} <--there might be more entries than these three of course
{['Name1']={score=235,x=6,y=88},
['Name2']={score=112,x=12,y=55},
['Name3']={score=15,x=15,y=56},}您可以使用一些在线工具测试您的正则表达式,例如
您还可以简化操作,不必使用正则表达式,而是通过以下子字符串来拆分字符串:[“”,这样您就可以得到一些带有子字符串的值数组:
0 -> {['Name1']={score=235,x=6,y=88
1 -> 'Name2']={score=112,x=12,y=55
2 -> 'Name3']={score=15,x=15,y=56},}
然后,您还可以将每个条目拆分为“]={”,您将
0.0 -> {['Name1'
0.1 -> score=235,x=6,y=88
1.0 -> 'Name2'
1.1 -> score=112,x=12,y=55
2.0 -> 'Name3'
2,1 -> score=15,x=15,y=56},}
……等等
这不是一个很好的解决方案,但它将帮助您在没有正则表达式的情况下完成任务。使用/\[\'(\w+)\]={score=(\d+),x=(\d+),y=(\d+)/
0.0 -> {['Name1'
0.1 -> score=235,x=6,y=88
1.0 -> 'Name2'
1.1 -> score=112,x=12,y=55
2.0 -> 'Name3'
2,1 -> score=15,x=15,y=56},}