dqb78642 2016-02-15 20:13
浏览 21
已采纳

REGEX获取“any_characters((number,number))”

I have this type of string:

some text that can contains anything ((12.1,5.2))another text that can contains anything ((1,8.7)) and so on...

And in fact I don't know how to get :

[0] some text that can contains anything ((12.1,5.2))

[1] another text that can contains anything ((1,8.7))

...

I tried: preg_match_all('#(.*\(\([0-9\.]+,[0-9\.]+\)\).*?)#',$lines,$match); but for sure it doesn't work. I also tried to add "U" option and ? after * and + but with no more results.

Thanks

  • 写回答

2条回答 默认 最新

  • dongyun9120 2016-02-15 20:20
    关注

    Try with this variation on what you have:

     preg_match_all('#.*?\(\([0-9.]+,[0-9.]+\)\)#',$lines,$match);
    

    The added question mark near the start is important , otherwise the dot will also consume the opening brackets. I also removed the part after the closing brackets, assuming your next line starts there.

    Also you do not need the overall capture group.

    The following

     if ($match !== false) {
          var_export ($match[0]);
     }
    

    will output:

    array (
      0 => 'some text that can contains anything ((12.1,5.2))',
      1 => 'another text that can contains anything ((1,8.7))',
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建