dtkmejg127475 2014-12-14 07:37
浏览 73
已采纳

正则表达式阵列多个括号

Hello I have api function which is basically text in my database

here are the functions I use

alpha(integer link, integer face, float alpha);
color(integer link, integer face, vector color, float alpha);
description(integer link, string description);
glow(integer link, integer face, glow);
name(integer link, string name)
position(integer link, vector position)
rotation(integer link, vector rotation)
texture(integer link, integer face, string texture_uuid, vector repeats, vector offsets, float rotation_in_radians)

basically what I looking to do is to run a regex to return each of these as array as I tried many times and not having much luck for example in textures I need pick the uuid key which I was using

([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})

which works fine for that one field but since I have other fields it does not seem to get into array as I not sure how to run multipliable regex

also the link and face can also be negative values as I was using (<[^>]*>|\w+) which works to a degree but not all the api functions

any idea how I can build regex to work on all api function types as I need them in array like this

array(
[0] = function,
[1] = link
[2] = face
[3] = texture uuid
[4] = texture repeats
[5] = offset
[6] = rotation
)

this is example using the texture function I hope I explained this enough as I having hard time here and looking for help

here example I was using

https://regex101.com/r/vO2gW1/3 as you see its broken as don't pick up uuid

or is there a way with regex or another method to execute these as functions even and keeping there structure as functions to return the data in format I need it for using PHP

  • 写回答

1条回答 默认 最新

  • dsbruqxgt820011351 2014-12-14 08:41
    关注

    You can try

    ^[^(]+(?=\()|(?<=[(,])\s*\K(?:<.*?>|.*?)(?=[,)])
    

    It should pick up everything you need. Demo.

    What it does is to match anything between the start of the string, commas and parentheses. So it won't work with stuff like anim(foo()).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路