douchen1988 2015-03-11 22:05
浏览 48
已采纳

preg_replace with Regex - 在URL中查找数字序列

I'm a regex-noobie, so sorry for this "simple" question:

I've got an URL like following:

http://stellenanzeige.monster.de/COST-ENGINEER-AUTOMOTIVE-m-w-Job-Mainz-Rheinland-Pfalz-Deutschland-146370543.aspx

what I'm going to archieve is getting the number-sequence (aka Job-ID) right before the ".aspx" with preg_replace.

I've already figured out that the regex for finding it could be

(?!.*-).*(?=\.)

Now preg_replace needs the opposite of that regular expression. How can I archieve that? Also worth mentioning:

The URL can have multiple numbers in it. I only need the sequence right before ".aspx". Also, there could be some php attributes behind the ".aspx" like "&mobile=true"

Thank you for your answers!

  • 写回答

3条回答 默认 最新

  • dsfdsf46465 2015-03-11 22:10
    关注

    You can use:

    $re = '/[^-.]+(?=\.aspx)/i'; 
    preg_match($re, $input, $matches);
    //=> 146370543
    

    This will match text not a hyphen and not a dot and that is followed by .aspx using a lookahead (?=\.aspx).

    RegEx Demo

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

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作