Mecano Posted October 14, 2014 Posted October 14, 2014 Hallo forum members, I am looking for a pattern to replace user= and password= between double quotes user="Alfa75" becomes user="*****" password="xstsgSvs" becomes password="*****" In my example the opposite happens, username and password is still visable StringReplace or StringRegExpReplace is not my best skill Opt("MustDeclareVars", 1) Global $Config = @ScriptDir & "\config.xml" _Config() Func _Config() If FileExists($Config) Then Local $file = FileOpen($Config, 0) Local $sData = FileRead($file) FileClose($file) Local $rData = StringRegExpReplace($sData, "(user=Chr(34)).+?(password=Chr(34)", "\1") ;$rData = StringReplace($rData, "user=", "*****") ; <-- desired with asterisk ;$rData = StringReplace($rData, "password=", "*****") ; <-- desired with asterisk $rData = StringReplace($rData, "user=", "") $rData = StringReplace($rData, "password=", "") MsgBox(0, "config.xml : ", $rData) ;ClipPut($rData) Else MsgBox(0, "config.xml : ", "Not found") EndIf EndFunc config.xml <config> <line short="LT" city="ASD" user="Alfa75" password="xstsgSvs" code="020" registered="1" period="20" /> <line short="IC" city="RTD" user="Jonh09" password="Gdte55567" code="010" registered="1" period="25" /> <line short="IB" city="UT" user="2ronals" password="B776656" code="030" registered="0" period="15" /> <line short="IC" city="RTD" user="DEjong67" password="=0gdd++00L==" code="010" registered="1" period="25" /> <line short="ST" city="AML" user="Eddy03" password=".te555=77Ai" code="036" registered="1" period="25" /> <line short="LT" city="CAS" user="BassB" password="+gdtWU=" code="0251" registered="1" period="35" /> <line short="IC" city="DT" user="lian033" password="77t--e55+=" code="015" registered="1" period="45" /> </config> desired result <config> <line short="LT" city="ASD" user="*****" password="*****" code="020" registered="1" period="20" /> <line short="IC" city="RTD" user="*****" password="*****" code="010" registered="1" period="25" /> <line short="IB" city="UT" user="*****" password="*****" code="030" registered="0" period="15" /> <line short="IC" city="RTD" user="*****" password="*****" code="010" registered="1" period="25" /> <line short="ST" city="AML" user="*****" password="*****" code="036" registered="1" period="25" /> <line short="LT" city="CAS" user="*****" password="*****" code="0251" registered="1" period="35" /> <line short="IC" city="DT" user="*****" password="*****" code="015" registered="1" period="45" /> </config>
alienclone Posted October 14, 2014 Posted October 14, 2014 you are telling it to replace "user=" and "password=" with "", instead of telling it to replace the text following those words. If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version
Mecano Posted October 14, 2014 Author Posted October 14, 2014 you are telling it to replace "user=" and "password=" with "", instead of telling it to replace the text following those words. I know, the point is I don't know the words between the double quotes, they always differed. After user=" replace the unknown word (characters) with ***** and do the same with password="
Solution mikell Posted October 14, 2014 Solution Posted October 14, 2014 (edited) Local $rData = StringRegExpReplace($sData, '(user|password)="\K[^"]+', "****") Edited October 14, 2014 by mikell
Malkey Posted October 14, 2014 Posted October 14, 2014 This also appears to work. Local $rData = StringRegExpReplace($sData, '(?<=user="|password=")[^"]+', '*****')
Mecano Posted October 14, 2014 Author Posted October 14, 2014 I did look @ http://www.autoitscript.com/autoit3/pcrepattern.html#resetmatchstart But to much for a "seeker" Works like a charm Thanks,
mikell Posted October 14, 2014 Posted October 14, 2014 K says : "Mr regex, please just forget what you have seen mentioned before me" Very useful sometimes
Mecano Posted October 15, 2014 Author Posted October 15, 2014 Tanks for the after service Useful information!
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