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/FILE_ID/edit?usp=sharing
and needs to be converted to look like this:
https://drive.google.com/uc?export=download&id=FILE_ID
So I'm trying to make my regex, which I'm not very experienced with, to grab the needed text to be deleted/changed. I'm using RegExr to try to create it, but I only get as far as
/file/d/
I've tried a negative lookahead, but it doesn't seem to work. Any suggestions?
UPDATED ON 23 March 2017
For PHP:
For Python:
For Perl:
For Java:
For Ruby:
For C#:
For R Language:
For Javascript:
For TCL:
for Oracle:
For C++:
For Groovy:
For PostgreSQL:
For VisualBasic.NET:
For Delphi XE:
For PowerShell:
For Xpath:
For VBscript:
If you need a different language just let me know! :)
This works in PCRE, in regex101:
^(https:\/\/drive\.google\.com\/)file\/d\/([^\/]+)\/.*$
$1uc?export=download&id=$2
Please consider bookmarking the Stack Overflow Regular Expressions FAQ for future reference.
You don't need regex for that you can complete the url transformation with 2 chained string replace. See for example this (in Java) :
==> The output: