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

前端之家收集整理的这篇文章主要介绍了正则表达式修改Google云端硬盘共享文件网址前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个脚本,将常规的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")

如果您需要其他语言,请告诉我! 原文链接:https://www.f2er.com/regex/356768.html

猜你在找的正则表达式相关文章