douyangquan2474 2014-12-31 15:39
浏览 32
已采纳

PHP Regex无法正常运行

I have a variable that can receive these two values:

'01838723001603 TELO 155' ou '01838723009850 0608'.

I want to get the second value after the number of 14 characters. For that, I'm trying the following regular expression, but it is not working:

/[0-9]{14} (.*?)/i

preg_match_all('/[0-9]{14} (.*?)/i', $data, $result);
var_dump($result);

Result -> [0 => '01838723026436', 1 => '01838723026436'].

She's just taking the first value (01838723001603).
I want her to return values: 'TELO 155' / '0608'

(this has to be done using regular expression, because these data are being captured from a text file)

  • 写回答

2条回答 默认 最新

  • douyi3767 2014-12-31 15:46
    关注

    You can try look behinds as

    /?<=\d{14}\s)[^']+/
    

    Regex Demo

    preg_match_all("/(?<=\\d{14}\\s)[^']+/", "01838723001603 TELO 155' ou '01838723009850 0608'.", $matches);
    

    will give output as

    Array ( [0] => Array 
                     ( [0] => TELO 155 
                       [1] => 0608 ) 
          ) 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥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线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错