[英]php regex start at the second occurrence of a character?
I've been fighting with this for a while, i have this string : storage/12426--the sunflower boys--07-09-2014/Authorization letter/Authorization letter--4--09-15-2015--15-39.pdf
我已经为此奋斗了一段时间,我有这个字符串:
storage/12426--the sunflower boys--07-09-2014/Authorization letter/Authorization letter--4--09-15-2015--15-39.pdf
and I would love to only get this part 07-09-2014
which lies between the first two slashes.我很想只得到这部分
07-09-2014
,它位于前两个斜线之间。
So far I came up with this: --[^/]*
which only gives me --the sunflower boys--07-09-2014
.到目前为止,我想出了这个:
--[^/]*
它只给了我--the sunflower boys--07-09-2014
。
How do I get what im looking for?我如何得到我正在寻找的东西?
使用数字\\d
匹配:
/^[^/]*\/[^/]*(\d\d-\d\d-\d\d\d\d)\//
You can use a capture group within 2 negated character class :您可以在 2 个否定字符类中使用捕获组:
\/[^\/]*(\d{2}-\d{2}-\d{4})[^\/]*\/
See demo https://regex101.com/r/mL3aF7/1见演示https://regex101.com/r/mL3aF7/1
如果格式一致,您可以拆分/
并取第二组,然后拆分--
取第三组。
$date = explode('--', explode('/', $str)[1])[2];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.