Jump to content

Recommended Posts

I have a proxy file with many ips, and i need find all line with <Username>iucbzmbl-xx</Username>  and replace "xx" to 100, next 101, next 102

This:

<Proxy id="170" type="HTTPS">
      <Address>142.44.223.144</Address>
      <Port>80</Port>
      <Options>48</Options>
      <Authentication enabled="true">
        <Username>iucbzmbl-51</Username>
        <Password></Password>
      </Authentication>
    </Proxy>
    <Proxy id="171" type="HTTPS">
      <Address>142.44.223.144</Address>
      <Port>80</Port>
      <Options>48</Options>
      <Authentication enabled="true">
        <Username>iucbzmbl-59</Username>
        <Password></Password>
      </Authentication>
    </Proxy>
    <Proxy id="172" type="HTTPS">
      <Address>142.44.223.144</Address>
      <Port>80</Port>
      <Options>48</Options>
      <Authentication enabled="true">
        <Username>iucbzmbl-62</Username>
        <Password></Password>
      </Authentication>
    </Proxy>

To this:

<Proxy id="170" type="HTTPS">
      <Address>142.44.223.144</Address>
      <Port>80</Port>
      <Options>48</Options>
      <Authentication enabled="true">
        <Username>iucbzmbl-100</Username>
        <Password></Password>
      </Authentication>
    </Proxy>
    <Proxy id="171" type="HTTPS">
      <Address>142.44.223.144</Address>
      <Port>80</Port>
      <Options>48</Options>
      <Authentication enabled="true">
        <Username>iucbzmbl-101</Username>
        <Password></Password>
      </Authentication>
    </Proxy>
    <Proxy id="172" type="HTTPS">
      <Address>142.44.223.144</Address>
      <Port>80</Port>
      <Options>48</Options>
      <Authentication enabled="true">
        <Username>iucbzmbl-102</Username>
        <Password></Password>
      </Authentication>
    </Proxy>

I searched about, found this function: https://www.autoitscript.com/autoit3/docs/functions/StringReplace.htm

How can i search the bold part <Username>iucbzmbl-xx</Username> and replace it in the function adding +1 to each value found. 😦

$String = 'C:\Users\CAIO\Downloads\proxy2.ppx'
StringReplace ( $string, "iucbzmbl", "replacestring"  )

 

Link to post
Share on other sites

Try this example.

#cs
<Proxy id="170" type="HTTPS">
      <Address>142.44.223.144</Address>
      <Port>80</Port>
      <Options>48</Options>
      <Authentication enabled="true">
        <Username>iucbzmbl-51</Username>
        <Password></Password>
      </Authentication>
    </Proxy>
    <Proxy id="171" type="HTTPS">
      <Address>142.44.223.144</Address>
      <Port>80</Port>
      <Options>48</Options>
      <Authentication enabled="true">
        <Username>iucbzmbl-59</Username>
        <Password></Password>
      </Authentication>
    </Proxy>
    <Proxy id="172" type="HTTPS">
      <Address>142.44.223.144</Address>
      <Port>80</Port>
      <Options>48</Options>
      <Authentication enabled="true">
        <Username>iucbzmbl-62</Username>
        <Password></Password>
      </Authentication>
    </Proxy>
#ce

Local $String = StringRegExpReplace(FileRead(@ScriptFullPath), "(?is)^.*?#cs\s+|\s+#ce.*$", "") ; Get test $String from comment block in this script.
; or
;Local $String = FileRead('C:\Users\CAIO\Downloads\proxy2.ppx')

Local $sStart = "<Username>iucbzmbl-"
Local $sEnd = "</Username>"
Local $iInit = 100 - 1
ConsoleWrite(Execute("'" & StringRegExpReplace($String, "(?i)(?<=" & $sStart & ")(\d+)(?=" & $sEnd & ".*?)", "'&$iInit+Assign('iInit',$iInit+1)&'") & "'") & @CRLF)

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...