Regex to modify Google Drive shared file URL

后端 未结 4 885
萌比男神i
萌比男神i 2021-02-04 16:37

I\'m trying to create a script to convert a regular google drive share URL to a direct download URL. The raw URL looks like this:

https://drive.google.com/file/d         


        
4条回答
  •  Happy的楠姐
    2021-02-04 17:00

    You don't need regex for that you can complete the url transformation with 2 chained string replace. See for example this (in Java) :

    String url="https://drive.google.com/file/d/FILE_ID/edit?usp=sharing";
    url = url.replace("/file/d/", "/uc?export=download&id=").replace("/edit?usp=sharing", "");
    System.out.print(url); 
    

    ==> The output:

    https://drive.google.com/uc?export=download&id=FILE_ID
    

提交回复
热议问题