簡體   English   中英

如何在 Invoke-WebRequest 中使用正則表達式

[英]How to use regex with Invoke-WebRequest

I want to fetch the latest 64 bit Git for Windows using the Invoke-WebRequest command and here's the Regex for it https://github.com/git-for-windows/git/releases/latest/download/Git-([0-9]+(\.[0-9]+)+)-64-bit\.exe

(64 位二進制文件命名為Git-[numbershere]-64-bit.exe ,例如Git-2.34.1-64-bit.exe

現在,我不知道如何將它與Invoke-WebRequest配對以使其工作。 有人可以幫忙嗎?

正如Jeroen Mostert 指出的那樣你沒有

相反,您可以使用GitHub 的公共 API來獲取有關最新版本的元數據,然后從那里選擇適當的 url:

# fetch metadata for latest release
$latestRelease = Invoke-RestMethod "https://api.github.com/repos/git-for-windows/git/releases/latest" 

# enumerate included assets, find the appropriate one
$exe64bit = $latestRelease.assets |Where-Object name -like 'Git-*-64-bit.exe'

# output the appropriate browser URL
$exe64bit.browser_download_url

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM