mlloz Posted June 9, 2009 Posted June 9, 2009 is that correct? or how to correct it? StringRegExpReplace($HostText, '[.(0-9)\t]' & 'Server', $NewIP) '[.(0-9)\t]' & 'Server' represent an IP Address followed by a tab then the name of the machine, $NewIP contains the replacement text.
Authenticity Posted June 10, 2009 Posted June 10, 2009 No Can you post an example of the $HostText content? [.(0-9)\t] means match ( or ) or 0 or - or 9 or tab or a dot heh.
Xand3r Posted June 10, 2009 Posted June 10, 2009 #include <Array.au3> Local $sString = "some prefix 89.43.123.165 test some suffix" $repl="'teste'" $s=StringRegExpReplace($sString,"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\ttest" , $repl) MsgBox(0 , "" , $sString& @CRLF &$s) Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro
mlloz Posted June 10, 2009 Author Posted June 10, 2009 Authenticity well, the example of the $HostText is the hosts file in the system directory.. like 192.168.1.12 Client1 #192.168.1.1 Server 89.43.123.165 Server here I want to replace just the second IP Address with the replacement text. Xand3r: it doesn't work
Authenticity Posted June 10, 2009 Posted June 10, 2009 Dim $sStr, $sIpPattern, $sNewIP $sStr = _ '192.168.1.12 Client1' & @CRLF & _ '#192.168.1.1 Server' & @CRLF & _ '89.43.123.165 Server' $sIpPattern = '\b(?>(?:[01]?\d?\d|25[0-5]|2[0-4]\d)\.){3}(?:[01]?\d?\d|25[0-5]|2[0-4]\d)\b' $sNewIP = @IPAddress1 & ' server' ConsoleWrite(StringRegExpReplace($sStr, '(?i)(?m)(?<!^)' & $sIpPattern & '\sserver', $sNewIP) & @LF)oÝ÷ Øâ·lê®·¶µÈmâi×kzË(¢~Þqç^u¼«!²('jw_¢YhÁç[Ê+®÷«þ,¨ºf²Á©í¶!jxÛhjëh×6StringRegExpReplace($sStr, '#' & $sIpPattern & '\sserver', $sNewIP)
mlloz Posted June 10, 2009 Author Posted June 10, 2009 yes Authenticity, it worked, and its difficult to understand but i need to change just the second entry, and it replaces all occurrences..
Authenticity Posted June 10, 2009 Posted June 10, 2009 Changing only the second one in this string requires only to split it on carriage return and line-feed and changing the second subscript of the array to the new string without using any of the string functions. But comparing to the real file it may not be the second line . You'll need to find another way to uniquely identify the specific line you want to replace.
mlloz Posted June 10, 2009 Author Posted June 10, 2009 i'm not going to sleep until i find that way..
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now