Regular Expression to collect everything after the last /

前端 未结 8 1890
北荒
北荒 2020-11-28 05:16

I\'m new at regular expressions and wonder how to phrase one that collects everything after the last /.

I\'m extracting an ID used by Google\'s GData.

8条回答
  •  不知归路
    2020-11-28 05:58

    Generally:

    /([^/]*)$
    

    The data you want would then be the match of the first group.


    Edit   Since you’re using PHP, you could also use strrchr that’s returning everything from the last occurence of a character in a string up to the end. Or you could use a combination of strrpos and substr, first find the position of the last occurence and then get the substring from that position up to the end. Or explode and array_pop, split the string at the / and get just the last part.

提交回复
热议问题