Why is my regular expression incorrect?

Source: Internet
Author: User
Why is my regular expression incorrect $ url = "http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml"; my goal is to retrieve 039bf460-2ea why is my regular expression incorrect
$ Url = "http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml ";

My goal is to retrieve 039bf460-2eaa-4098-89e2-fa07512a8588

Written in this way

// Obtain the video id
Preg_match ('/\/(.*)?. Shtml/', $ url, $ videoID );
Print_r ($ videoID );

Why not? Please advise. Thank you.



------ Solution --------------------
\/(.*)?. The shtml regular expression indicates a string of characters starting from/and ending with shtml. if you want to obtain it, use the following method:
$url="http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml";
$path = pathinfo($url);
var_dump($path['filename'])

------ Solution --------------------
$url="http://v.ifeng.com/documentary/figure/2014002/039bf460-2eaa-4098-89e2-fa07512a8588.shtml";

preg_match('/([^\/]*?).shtml/',$url, $videoID);
print_r($videoID);
Array
(
[0] => 039bf460-2eaa-4098-89e2-fa07512a8588.shtml
[1] => 039bf460-2eaa-4098-89e2-fa07512a8588
)

------ Solution --------------------
Preg_match ('/\/(.*?) \. Shtml/', $ url, $ videoID );
------ Solution --------------------
Echo basename ($ url, ". shtml ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.