我是正则表达式的新手,不知道如何表达一个收集最后一个/之后的所有内容的正则表达式。
我正在提取谷歌GData使用的ID。
我的示例字符串是
http://spreadsheets.google.com/feeds/spreadsheets/p1f3JYcCu_cb0i0JYuCu123其中ID为:p1f3JYcCu_cb0i0JYuCu123
哦,我用的是PHP。
发布于 2017-09-01 15:28:32
根据@Mark Rushakoff的回答,不同情况下的最佳解决方案:
<?php
$path = "http://spreadsheets.google.com/feeds/spreadsheets/p1f3JYcCu_cb0i0JYuCu123?var1&var2#hash";
$vars =strrchr($path, "?"); // ?asd=qwe&stuff#hash
var_dump(preg_replace('/'. preg_quote($vars, '/') . '$/', '', basename($path))); // test.png
?>https://stackoverflow.com/questions/1150559
复制相似问题