Thanks to anyone who offers improvements.
Working code.
#include <Array.au3> ; For _ArrayDisplay. Example() Func Example() Local $sData = FileRead(@SystemDir & '\drivers\etc\HOSTS') ; Strip comments e.g. # This is a single comment. # $sData = StringRegExpReplace($sData, '#.*', '') ; Strip forwarding IP address e.g. 127.0.0.1 $sData = StringRegExpReplace($sData, '(?m)^\s*(?:\d{1,3}\.){3}\d{1,3}', '') ; Parse HOSTS file to create an array with the hostnames in the file. Local $aArray = StringRegExp(' HOSTS_Count ' & $sData, '(?:[\w\.\-/]{3,})', 3) ; Past ideas: '((?:\d{1,3}\.){3}\d{1,3})\s+(.*?)\r\n' ... '((?:[\w\-]*\.+)+[\w\-]*)' If @error Then MsgBox(4096, '', 'An error occurred when parsing the HOSTS file.') Else ; Replace the 0th element with the number of items in the array. $aArray[0] = UBound($aArray, 1) - 1 ; Ask whether or not to display the array using _ArrayDisplay, can be slow depending on how large your HOSTS file is. If MsgBox(4 + 4096, '', 'Would you like to display the Array? (Could be slow depending on how large you HOSTS file is.)') = 6 Then _ArrayDisplay($aArray) EndIf EndIf EndFunc ;==>Example
Updated: With suggestions by Spiff59.
Edited by guinness, 24 May 2012 - 10:47 PM.







