加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式修改Google云端硬盘共享文件网址

发布时间:2020-12-14 06:22:36 所属栏目:百科 来源:网络整理
导读:我正在尝试创建一个脚本,将常规的Google云端硬盘共享网址转换为直接下载网址.原始URL如下所示: https://drive.google.com/file/d/FILE_ID/edit?usp=sharing 并需要转换为如下所示: https://drive.google.com/uc?export=downloadid=FILE_ID 因此,我正在尝试
我正在尝试创建一个脚本,将常规的Google云端硬盘共享网址转换为直接下载网址.原始URL如下所示:
https://drive.google.com/file/d/FILE_ID/edit?usp=sharing

并需要转换为如下所示:

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

因此,我正在尝试使用我不熟悉的正则表达式来获取要删除/更改的所需文本.我正在使用RegExr尝试创建它,但我只能得到它

/file/d/

我尝试过一种消极的前瞻,但它似乎没有用.有什么建议?

2017年3月23日更新

对于PHP:

$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(r"https://drive.google.com/file/d/(.*?)/.*??usp=sharing",r"https://drive.google.com/uc?export=download&id=1",url)

对于Perl:

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

对于Java:

String 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#:

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} $subject "https://drive.google.com/uc?export=download&id=1" result

对于Oracle:

result := REGEXP_REPLACE(subject,'https://drive.google.com/file/d/(.*)/.*??usp=sharing','https://drive.google.com/uc?export=download&id=1',1,'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")

对于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")

对于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:replace($input,"https://drive.google.com/file/d/(.*?)/.*??usp=sharing","https://drive.google.com/uc?export=download&id=$1")

对于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")

如果您需要其他语言,请告诉我!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读