dsyct08008 2016-01-29 17:19
浏览 110
已采纳

序列化数据中的正则表达式

I am looking to a database search on serialized data. I am currently using Symfony2 as my Framework making pdo_mysql calls using Doctrine 2. What I would like to do is create a query that uses REGEXP to find data within a certian part of the array. The data I am trying to search within looks like this: -

a:1:{s:8:"bedrooms";a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;s:2:"5+";}}

So let's say I am looking for a record that has 3 bedrooms, then I would want it to find: -

i:2;i:3

The query I have come up with so far is: -

SELECT * FROM table WHERE field_name REGEXP '.*"bedrooms"; a:[0-9]+:{i:[0-9]+;i:3;}.*';

However this doesn't work. Can someone help me find a fix around this please? I think it's down to the way the regular expression is written.

Also its worth noting that there are other arrays stored in the field such credit limits and other data.

Thank you in advance.

  • 写回答

2条回答 默认 最新

  • doyrte8419 2016-01-29 17:23
    关注

    I believe you can do it with the help of negated character class [^{}] that matches any character but a { and }:

    .*"bedrooms";a:[0-9]+:[{][^{}]*i:[0-9]+;i:3[^{}]*[}]
    

    See the regex demo

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

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C