Jump to content

Recommended Posts

Posted

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.

Posted

#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

Posted

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

Posted

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)

Posted

yes Authenticity, it worked, and its difficult to understand :D

but i need to change just the second entry, and it replaces all occurrences..

Posted

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 :D . You'll need to find another way to uniquely identify the specific line you want to replace.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...