正则表达式来修改Google云端硬盘共享文件的URL [英] Regex to modify Google Drive shared file URL

查看:146
本文介绍了正则表达式来修改Google云端硬盘共享文件的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个脚本来将常规的Google云端硬盘共享网址转换为直接下载网址。原始网址如下所示:

  https://drive.google.com/file/d/FILE_ID/edit?usp =分享

,需要转换成如下所示:

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

所以我试图让我的正则表达式,我不是非常有经验,抓住需要删除/改变的文本。我使用RegExr来尝试创建它,但我只得到

  / file / d / 

我尝试了一种负面预测,但似乎无法正常工作。任何建议?

解决方案

$ b




适用于PHP: $ b

  $ link = preg_replace('%https://drive\.google\.com/file/d/(。*?)/.*?\?usp=sharing%','https:// drive。 google.com/uc?export=download&id=$1',$ link); 

对于Python:

  result = re.sub(rhttps://drive\.google\.com/file/d/(。*?)/.*?\ ?usp = sharing,rhttps://drive.google.com/uc?export=download&id=\1,url)

Perl:

  $ subject =〜小号的https://drive\.google\.com/file/d/ /.*?\?usp=sharing!https://drive.google.com/uc?export=(*?)下载和放大器;!ID = $1克; 

适用于Java:

 字符串resultString = subjectString.replaceAll(https://drive\\.google\\.com/file/d/(。*?)/。 *?\\?usp = sharing,https://drive.google.com/uc?export=download&id=$1); 

对于Ruby:

  result = subject.gsub(/https:\/\/drive\.google\.com\/file\/d\/(。 *?)\ /.*?\?usp = sharing /,'https://drive.google.com/uc?export=download&id=\1')

 <$> 



c $ c> resultString = Regex.Replace(subjectString,@https://drive\.google\.com/file/d/(。*?)/.*?\?usp=sharing, https://drive.google.com/uc?export=download&id=$1\" );

对于R语言:

 〜gsub(https://drive\\.google\\.com/file/d/(。*?)/.*?\\ \\\?usp = sharing,https://drive.google.com/uc?export=download&id=\\1,subject,perl = TRUE); 

适用于Javascript:

  result = subject.replace(/https:\/\/drive\.google\.com\/file\/d\/(。 *?)\ /.*?\?usp = sharing / g,https://drive.google.com/uc?export=download&id=$1); 

对于TCL:

  regsub -linestop -all {https://drive\.google\.com/file/d/(。*?)/.*?\?usp = sharing} $ subjecthttps://drive.google.com/uc?export=download\\&id=\\ 1result 

 结果为p $ p> 

:= REGEXP_REPLACE(主题,'https://drive\.google\.com/file/d/(。*)/.*?\?usp=sharing','https://drive.google。 com / uc?export = download& id = \ 1',1,0,'c');

对于C ++:

  wxString; 
wxRegEx regexObj(_T((?p)\\Ahttps://drive\\.google\\.com/file/d/(。*?)/.*?\\ \\\?usp = sharing),wxRE_ADVANCED);
regexObj.ReplaceAll(& subjectString,_T(https://drive.google.com/uc?export=download\\&id=\\1));

对于Groovy:

  Matcher regexMatcher = subjectString =〜/https:\/\/drive\\..google\.com\/file\/d\/(。 *?)\ /.*?\?usp = sharing / 
String resultString = regexMatcher.replaceAll('https://drive.google.com/uc?export=download&id=$1');

对于PostgreSQL:

  SELECT REGEXP_REPLACE(mycolumn,$$(?p)https://drive\.google\.com/file/d/(。*?)/.* ?\?usp = sharing $$,$$ https://drive.google.com/uc?export = download& id = \ 1 $$,'g')FROM mytable; 

对于VisualBasic.NET:

  Dim RegexObj As New Regex(https://drive\.google\.com/file/d/(。*?)/.*?\\ \\?usp = sharing)
ResultString = RegexObj.Replace(SubjectString,https://drive.google.com/uc?export=download&id=$1)

 

code> Dim RegexObj As New Regex(https://drive\.google\.com/file/d/(。*?)/.*?\?usp=sharing)
ResultString = RegexObj.Replace(SubjectString,https://drive.google.com/uc?export=download&id=$1)

对于PowerShell:

  $ regex = [regex] 'https://drive\.google\.com/file/d/(。*?)/.*?\?usp=sharing'
$ result = $ regex.Replace($ subject, 'https://drive.google.com/uc?export=download&id=$1')

对于Xpath:

  fn:replac e($ input,https://drive\.google\.com/file/d/(。*?)/.*?\?usp=sharing,https://drive.google。 com / uc?export = download& amp; amp; id = $ 1)



  Dim myRegExp,ResultString 
Set myRegExp = New RegExp
myRegExp.Global = True
myRegExp.Pattern =https://drive\.google\.com/file/d/(。*?)/.*?\?usp=sharing
ResultString = myRegExp .Replace(SubjectString,https://drive.google.com/uc?export=download&id=$1)

如果您需要不同的语言,请告诉我! :)

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:

$link = preg_replace('%https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing%', 'https://drive.google.com/uc?export=download&id=$1', $link);

For Python:

result = re.sub(r"https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing", r"https://drive.google.com/uc?export=download&id=\1", url)

For Perl:

$subject =~ s!https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing!https://drive.google.com/uc?export=download&id=$1!g;

For Java:

String resultString = subjectString.replaceAll("https://drive\\.google\\.com/file/d/(.*?)/.*?\\?usp=sharing", "https://drive.google.com/uc?export=download&id=$1");

For Ruby:

result = subject.gsub(/https:\/\/drive\.google\.com\/file\/d\/(.*?)\/.*?\?usp=sharing/, 'https://drive.google.com/uc?export=download&id=\1')

For C#:

resultString = Regex.Replace(subjectString, @"https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing", "https://drive.google.com/uc?export=download&id=$1");

For R Language:

~gsub("https://drive\\.google\\.com/file/d/(.*?)/.*?\\?usp=sharing", "https://drive.google.com/uc?export=download&id=\\1", subject, perl=TRUE);

For Javascript:

result = subject.replace(/https:\/\/drive\.google\.com\/file\/d\/(.*?)\/.*?\?usp=sharing/g, "https://drive.google.com/uc?export=download&id=$1");

For TCL:

regsub -linestop -all {https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing} $subject "https://drive.google.com/uc?export=download\\&id=\\1" result

for Oracle:

result := REGEXP_REPLACE(subject, 'https://drive\.google\.com/file/d/(.*)/.*?\?usp=sharing', 'https://drive.google.com/uc?export=download&id=\1', 1, 0, 'c');

For C++:

wxString ;
wxRegEx regexObj(_T("(?p)\\Ahttps://drive\\.google\\.com/file/d/(.*?)/.*?\\?usp=sharing"), wxRE_ADVANCED);
regexObj.ReplaceAll(&subjectString, _T("https://drive.google.com/uc?export=download\\&id=\\1"));

For Groovy:

Matcher regexMatcher = subjectString =~ /https:\/\/drive\.google\.com\/file\/d\/(.*?)\/.*?\?usp=sharing/
String resultString = regexMatcher.replaceAll('https://drive.google.com/uc?export=download&id=$1');

For PostgreSQL:

SELECT REGEXP_REPLACE(mycolumn, $$(?p)https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing$$, $$https://drive.google.com/uc?export=download&id=\1$$, 'g') FROM mytable;

For VisualBasic.NET:

Dim RegexObj As New Regex("https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing")
ResultString = RegexObj.Replace(SubjectString, "https://drive.google.com/uc?export=download&id=$1")

For Delphi XE:

Dim RegexObj As New Regex("https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing")
ResultString = RegexObj.Replace(SubjectString, "https://drive.google.com/uc?export=download&id=$1")

For PowerShell:

$regex = [regex] 'https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing'
$result = $regex.Replace($subject, 'https://drive.google.com/uc?export=download&id=$1')

For Xpath:

fn:replace($input, "https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing", "https://drive.google.com/uc?export=download&amp;id=$1")

For VBscript:

Dim myRegExp, ResultString
Set myRegExp = New RegExp
myRegExp.Global = True
myRegExp.Pattern = "https://drive\.google\.com/file/d/(.*?)/.*?\?usp=sharing"
ResultString = myRegExp.Replace(SubjectString, "https://drive.google.com/uc?export=download&id=$1")

If you need a different language just let me know! :)

这篇关于正则表达式来修改Google云端硬盘共享文件的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆