gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:01:28 27 4
gpt4 key购买 nike

我正在尝试创建一个脚本,将常规的Google驱动器共享URL转换为直接下载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, 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")

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

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

关于正则表达式修改Google云端硬盘共享文件网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23224590/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com