我有一個決議 URL 的腳本。如果查詢包含用戶和密碼,它將檢索它。
因此,如有必要,我想保留 PHP 查詢。
Add-Type -AssemblyName System.Web
$url = "http://toto.site:8080/user/password12349876toolong/2716?checkedby:toto.net"
$uri = [System.Uri]$url
$query = $uri.Query
$IPTVhost = $uri.Host
$IPTVport = $uri.Port
$Segments = $uri.Segments.TrimEnd('/')
$proto = $uri.Scheme
$ParsedQueryString = [System.Web.HttpUtility]::ParseQueryString($uri.Query)
if(!$query) {
if ($Segments[1].TrimEnd('/') -eq "live"){
$username = $Segments[2].TrimEnd('/')
$password = $Segments[3].TrimEnd('/')
}
else
{
$username = $Segments[1].TrimEnd('/')
$password = $Segments[2].TrimEnd('/')
}
}
else {
$username = $ParsedQueryString['username']
$password = $ParsedQueryString['password']
}
cls
if (!($url -like '\?checkedby\:'))
{
echo "this is a chekedby url"
$filter = $url.TrimEnd("\?checkedby\:toto.net")
echo "filter : $filter"
}
echo "url: $url"
echo "query: $query"
echo "host: $IPTVhost"
echo "port: $IPTVport"
echo "segment: $Segments"
echo "proto: $proto"
echo "username: $username"
echo "password: $password"
當我在腳本中輸入 URL 時,我想過濾一串字符(通常在查詢中找到,但并非總是如此)。我知道它總是以"? Checkedby:"or開頭,"& checkedby:"并且總是在 url 的末尾。
有問題:鏈是可變的,它可以是:
http://toto.com:8080/get.php?username=toto&password=toto&checkedby:titi.com
或者
http://toto.com/1234/4321/5678?checkedby:anyone.xyz
或者
http://toto.com/1234/4321/5678?master.m3u8&checkedby:anyelse.to
或者這個廢話:
http://toto.com:8080/get.php?username=toto&password=toto&type=output.ext?checkedby:titi.com
我已經用 TrimEnd 嘗試了幾種方法,但沒有任何幫助。唯一有效的是一個精確的運算式,如:
$filter = $url.TrimEnd("\?checkedby\:toto.net")
但這對以以下結尾的網址不起作用(這是正常的):
&checkedby:another.com.
所以,問題:
如何洗掉以以下開頭的所有內容:
&checkedby:
或者
?checkedby:
謝謝你。
uj5u.com熱心網友回復:
基于Santiago Squarzon 的有用評論:
通過運算子使用基于正則運算式的操作:-replace
'http://toto.com:8080/get.php?username=toto&password=toto&checkedby:titi.com',
'http://toto.com/1234/4321/5678?checkedby:anyone.xyz',
'http://toto.com/1234/4321/5678?master.m3u8&checkedby:anyelse.to',
'http://toto.com:8080/get.php?username=toto&password=toto&type=output.ext?checkedby:titi.com' |
ForEach-Object { $_ -replace '[?&]checkedby:. ' }
有關正則運算式的說明以及試驗它的選項,請參閱此 regex101.com 頁面。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/366194.html
標籤:电源外壳
