[英]Regular Expressions
我需要從主機文件中獲取兩個IP地址。 我是正則表達式的新手,並使用以下代碼。 它可以正常工作,但它正在獲取列出的所有IP。
運行以下腳本時,結果如下:
102.54.94.97 38.25.63.10 127.0.0.1 10.104.134.41 10.104.134.42 10.0.45.90 10.0.45.92 10.0.45.93 10.0.45.94 10.0.45.95 10.0.45.96 10.0.45.97 10.0.45.98
$input_path = ‘c:\temp\Hosts’
$output_file = ‘c:\temp\test.txt’
$regex = ‘\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b’
select-string -Path $input_path -Pattern $regex -AllMatches | % {
$_.Matches } | % { $_.Value } > $output_file
我期望僅獲取兩個IP:
10.104.134.41和10.104.134.42
第一個八位位組將始終為10,最后一個八位位組將始終為.41和.42
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.