Jump to content

StringRegExpReplace


Recommended Posts

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.

Link to comment
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

Link to comment
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

Link to comment
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)

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...