douliao8760 2012-11-26 09:00
浏览 27
已采纳

找出是否:-char介于[和]之间

I'm looking for a solution to find if a :-char is enclosed by [ and ] or not.

I have a sort of syntax which enables to define keys with corresponding values in a template. The syntax is exploded by :-char to identify the keys, but a :-char should also be valid if it's within the brackets. Basically my sample/case is like:

:key1[value]:key2[this:value should work too].

I'm looking for a way to find if :-char is within the brackets. I've started writing out a procedure to figure this out, but somewhere during the writing an electronic pulse in my mind said 'regex.. regex'. But I'm quite unfamiliar with them. Could someone help me out?

P.s. if you're downvoting the question, at least tell me why you think its a bad question. In my opinion its a correct question I'm asking assistance for.

  • 写回答

3条回答 默认 最新

  • douxuanou2787 2012-11-26 09:07
    关注

    I'm gonna show you the general way to parse this: DEMO

    :(key\d)+\[([^\]]+)\]

    What you need to do is match everything between [ and ] so instead of using .* you must tell the Regular Expression that you want to MATCH EVERYTHING that is not ] so... [^\]]

    You can see the demo for more explanation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP