dongliugu8843 2014-10-07 15:59
浏览 220

正则表达式 - 从重复格式中提取字符串

EDIT - SOLVED:
Thanks for the responses - I learned that this is actually in serialised format and that there's no need to process it using RegEx.

Apologies for the newb question - and I have tried many many variations, based on StackOverflow answers with no luck. I've also spent a while experimenting with an online Regex tool to try and solve this myself.

This is the string I'm checking :

i:0;s:1:"1";i:1;s:1:"3";i:2;s:1:"5";i:3;s:1:"6";

I'll settle for matching these strings :

i:0;s:1:"1";
i:1;s:1:"3";
i:2;s:1:"5";
i:3;s:1:"6";

But ideally I would like to capture all the values between quotes only.
(there could be anywhere between 1-10 of these kinds of entries)
i.e. regex_result = [1,3,5,6]

These are some of the regexes I've tried. I've only been able to either capture the first match, or the last match, but not all matches - I'm confused as to why the regex isnt "repeating" as I'd expected:

(i:.;s:1:".";)*

(i:.;s:1:".";)+

(i:.;s:1:".";)+?

Thanks

  • 写回答

3条回答 默认 最新

  • doudang8824 2014-10-07 16:01
    关注

    You can use this regex.

    /(?<=:")\d+(?=";)/g
    

    DEMO

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘