2015-02-10 33 views
0

代碼:旁路列表創建代理失敗,如果它包含「*」

New-Object System.Net.WebProxy($Env:http_proxy, $true, @('localhost', '*.domain.com') 

失敗,出現錯誤:

New-Object : Exception calling ".ctor" with "3" argument(s): "parsing "*.domain.com" - Quantifier {x,y} following nothing." 
At line:1 char:6 
+ $p = New-Object System.Net.WebProxy($Env:http_proxy, $true, @('*.domain.com', 'l ... 

Quantifier {x,y} following nothing是正則表達式錯誤,很奇怪。我試圖使用正則表達式轉義字符,但沒有。

任何解決方案?

回答

1

我搞砸,截至至少兩次 - 以下然而似乎正確地添加它雖然一次一個:

$wp = New-Object System.Net.WebProxy($Env:http_proxy, $true) 
$wp.BypassArrayList.Add('localhost') 
$wp.BypassArrayList.Add('*.domain.com') 

輸出

Address    : 
BypassProxyOnLocal : True 
BypassList   : {localhost, *.domain.com} 
Credentials   : 
UseDefaultCredentials : False 
BypassArrayList  : {localhost, *.domain.com} 
1

尋找at this它規定的第三個參數是一個正則表達式字符串數組 - *.domain.com不是有效的正則表達式,因爲字符類必須位於*之前。

[PS] > New-Object System.Net.WebProxy($Env:http_proxy, $true, @("localhost.domain.com",".*.domain.com")) 


Address    : 
BypassProxyOnLocal : True 
BypassList   : {localhost.domain.com, .*.domain.com} 
Credentials   : 
UseDefaultCredentials : False 
BypassArrayList  : {localhost.domain.com, .*.domain.com} 
+0

感謝:

如果你把它改爲然而.*.domain.com它的工作原理。沒有注意到這個正則表達式的信息。 – majkinetor 2015-02-10 16:38:03