Sign in to follow this  
Followers 0
mlloz

StringRegExpReplace

9 posts in this topic

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.

Share this post


Link to post
Share on other sites



No :D

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.

Share this post


Link to post
Share on other sites

#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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

i'm not going to sleep until i find that way.. :D

Share this post


Link to post
Share on other sites
:D i'm thinking to change my mind

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0