jerem488 Posted February 1, 2009 Share Posted February 1, 2009 I have a string, $Array = "ch2ch3ch3ch4ch7ch1fr22ch2fr21ch3fr34ch4fr10r29rch1ch32ch2ch3ch3ch25ch4ch2ch1fr22ch2fr16ch3fr14c h4fr28r24rch1ch32ch2ch3ch3ch17ch4ch25" And i want check three last characters of the string finishs for "r" two digits and "r" I have tried it : $Count = StringLen(FileRead(@DesktopDir & "\Test.txt")) $LastCharacters = StringRegExp(StringTrimLeft(FileRead(@DesktopDir & "\test.txt"),$Count-3),"[r]\d{2}[r]") And if three last characters are different of "r" two digits and "r", i delete this portion string thank you Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
-Ultima- Posted February 1, 2009 Share Posted February 1, 2009 ...? Local $sWillGetStripped = "The following will get stripped: ABCD" Local $sWillNotGetStripped = "The following will not get stripped: r00r" ConsoleWrite(StripEnd($sWillGetStripped) & @CRLF) ConsoleWrite(StripEnd($sWillNotGetStripped) & @CRLF) Func StripEnd($sString) If Not StringRegExp($sString, "r\d{2}r$") Then $sString = StringTrimRight($sString, 4) Return $sString EndFunc Is this what you're looking to do? Your post isn't exactly clear, and your example code doesn't help us figure out what it is you mean. There are too many contradictions between what you said and what you coded. [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
jerem488 Posted February 1, 2009 Author Share Posted February 1, 2009 yes it's this ! You have understand the question ! Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 1, 2009 Moderators Share Posted February 1, 2009 (edited) ...? Local $sWillGetStripped = "The following will get stripped: ABCD" Local $sWillNotGetStripped = "The following will not get stripped: r00r" ConsoleWrite(StripEnd($sWillGetStripped) & @CRLF) ConsoleWrite(StripEnd($sWillNotGetStripped) & @CRLF) Func StripEnd($sString) If Not StringRegExp($sString, "r\d{2}r$") Then $sString = StringTrimRight($sString, 4) Return $sString EndFunc Is this what you're looking to do? Your post isn't exactly clear, and your example code doesn't help us figure out what it is you mean. There are too many contradictions between what you said and what you coded.I *think* this can be accomplished with 1 line of RegExReplaceStringRegExpReplace($sString, "(?i)(.+?r\d{2}r\z)|(.+?)(.{4}\z)", "\1\2") to look like:Local $sWillGetStripped = "The following will get stripped: ABCD" Local $sWillNotGetStripped = "The following will not get stripped: r00r" ConsoleWrite(StripEnd($sWillGetStripped) & @CRLF) ConsoleWrite(StripEnd($sWillNotGetStripped) & @CRLF) Func StripEnd($sString) Return StringRegExpReplace($sString, "(?i)(.+?r\d{2}r\z)|(.+?)(.{4}\z)", "\1\2") EndFuncBut, your way is probably how I would have approached it myself. Edit: Tested original expression I wrote, it failed... Tested above expression, it does seem to work. Edited February 1, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
jerem488 Posted February 1, 2009 Author Share Posted February 1, 2009 I tried this, $pattern = "ch2ch3ch3ch4ch7ch1fr22ch2fr21ch3fr34ch4fr10r29rch1ch32ch2ch3ch3ch25ch4ch2ch1fr22ch2fr16ch3fr14ch4fr28r24rch1ch32ch2ch3ch3ch17ch4ch25ch1fr14ch2fr28ch3fr2ch4fr33r25rch1ch32ch2ch17ch3ch33ch4ch23ch1fr24ch2fr13ch3fr1ch4fr6r22rch1ch32ch2ch17ch3ch33ch4ch0ch1fr3ch2fr32ch3fr19ch4fr11r8rch1ch32ch2ch31ch3ch33ch4ch17ch1fr27ch2fr19ch3fr33ch4fr24r34" StringRegExpReplace($pattern, "(?i)(.+?r\d{2}r\z)|(.+?)(....\z))", "\1\2") MsgBox(0,"",$pattern) and the result is the same string... Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 1, 2009 Moderators Share Posted February 1, 2009 (edited) I tried this, $pattern = "ch2ch3ch3ch4ch7ch1fr22ch2fr21ch3fr34ch4fr10r29rch1ch32ch2ch3ch3ch25ch4ch2ch1fr22ch2fr16ch3fr14ch4fr28r24rch1ch32ch2ch3ch3ch17ch4ch25ch1fr14ch2fr28ch3fr2ch4fr33r25rch1ch32ch2ch17ch3ch33ch4ch23ch1fr24ch2fr13ch3fr1ch4fr6r22rch1ch32ch2ch17ch3ch33ch4ch0ch1fr3ch2fr32ch3fr19ch4fr11r8rch1ch32ch2ch31ch3ch33ch4ch17ch1fr27ch2fr19ch3fr33ch4fr24r34" StringRegExpReplace($pattern, "(?i)(.+?r\d{2}r\z)|(.+?)(....\z))", "\1\2") MsgBox(0,"",$pattern) and the result is the same string...Try with the edited version I made before you posted this. Edit: You also have 1 too many closing parenthesis in that statement, I probably had that myself before I edited. Edited February 1, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
-Ultima- Posted February 1, 2009 Share Posted February 1, 2009 (edited) Because there was a slight syntax error in the matching pattern (notice the extra closing parenthesis at the end?), which SmOke_N already fixed (Edit: Bah, SmOke_N got to it first ). Also, StringRegExpReplace() doesn't modify the input string -- it returns the new string, so you're supposed to do something like $pattern = StringRegExpReplace(...) anyway.@SmOke_N: Yeah, I'm not entirely proficient in regex (though I can usually get my way around given a fair amount of time), so I didn't feel like thinking up anything more than an extremely sparse/simple regular expression ;DEdit: @jerem488: The only thing you really need to be careful with is the case insensitivity. If you do want it to strip something like "R00R" (because the "R"s are uppercase), then you need to remove the "(?i)" from the regular expression. Edited February 1, 2009 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
jerem488 Posted February 1, 2009 Author Share Posted February 1, 2009 Sorry... but I don't understand I msut put or try.... Local $sWillGetStripped = "The following will get stripped: ABCD" Local $sWillNotGetStripped = "The following will not get stripped: r00r" ConsoleWrite(StripEnd($sWillGetStripped) & @CRLF) ConsoleWrite(StripEnd($sWillNotGetStripped) & @CRLF) Func StripEnd($sString) Return StringRegExpReplace($sString, "(?i)(.+?r\d{2}r\z)|(.+?)(.{4}\z)", "\1\2") EndFunc and this code do nothing Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
-Ultima- Posted February 1, 2009 Share Posted February 1, 2009 It works. I see the following output in the console: The following will get stripped: The following will not get stripped: r00r [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 1, 2009 Moderators Share Posted February 1, 2009 (edited) Sorry... but I don't understand I msut put or try.... Local $sWillGetStripped = "The following will get stripped: ABCD" Local $sWillNotGetStripped = "The following will not get stripped: r00r" ConsoleWrite(StripEnd($sWillGetStripped) & @CRLF) ConsoleWrite(StripEnd($sWillNotGetStripped) & @CRLF) Func StripEnd($sString) Return StringRegExpReplace($sString, "(?i)(.+?r\d{2}r\z)|(.+?)(.{4}\z)", "\1\2") EndFunc and this code do nothing The code writes to the bottom pane (console ... Thus "ConsoleWrite") of your SciTe Editor. Try this:Local $sWillGetStripped = "The following will get stripped: ABCD" Local $sWillNotGetStripped = "The following will not get stripped: r00r" MsgBox(0, "Stripped String", StripEnd($sWillGetStripped)) MsgBox(0, "Not Stripped", StripEnd($sWillNotGetStripped)) Func StripEnd($sString) Return StringRegExpReplace($sString, "(?i)(.+?r\d{2}r\z)|(.+?)(.{4}\z)", "\1\2") EndFunc Edit: And Ultima was waiting for that one (Just to beat me!) Edited February 1, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
jerem488 Posted February 1, 2009 Author Share Posted February 1, 2009 (edited) yes the output return only The following will get stripped: The following will not get stripped: r00r else nothing Edited February 1, 2009 by jerem488 Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
jerem488 Posted February 1, 2009 Author Share Posted February 1, 2009 In a first time are you sure the expression "(?i)(.+?r\d{2}r\z)|(.+?)(.{4}\z)" is good ??How can I test this expression ?Since a time i tried to resolve this....unsuccessfully Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
jerem488 Posted February 1, 2009 Author Share Posted February 1, 2009 $pattern = "ch2ch3ch3ch4ch7ch1fr22ch2fr21ch3fr34ch4fr10r29rch1ch32ch2ch3ch3ch25ch4ch2ch1fr22ch2fr16ch3fr14ch4fr28r24rch1ch32ch2ch3ch3ch17ch4ch25ch1fr14ch2fr28ch3fr2ch4fr33r25rch1ch32ch2ch17ch3ch33ch4ch23ch1fr24ch2fr13ch3fr1ch4fr6r22rch1ch32ch2ch17ch3ch33ch4ch0ch1fr3ch2fr32ch3fr19ch4fr11r8rch1ch32ch2ch31ch3ch33ch4ch17ch1fr27ch2fr19ch3fr33ch4fr24r34" $array = StringRegExp($pattern, "(?i)(.+?r\d{2}r\z)|(.+?)(....\z))", "\1\2") for $i = 0 to UBound($array) - 1 msgbox(0, "RegExp result" & $i, $array[$i]) Next don't work....... Why ? Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
-Ultima- Posted February 1, 2009 Share Posted February 1, 2009 (edited) Because you're still not reading carefully. StringRegExp() is not StringRegExpReplace(). And once again, that regular expression you're using has a syntax error, so it won't work no matter what function you use it in anyway. SmOke_N's StripEnd() works perfectly well. Why are you avoiding it? Edited February 1, 2009 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
jerem488 Posted February 1, 2009 Author Share Posted February 1, 2009 because he don't return the good result. So I test with stringregexp() function. But I think i went continue to use stringregexpreplace function. but I really need help ! ! Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
jerem488 Posted February 1, 2009 Author Share Posted February 1, 2009 So, I go resume.I have a string (in a tex file) similar to this string "451025478152r12r894251502300154r91r202"And I want read this file by starting of the end. And while three last character of the file are different of this regular expression ==> "r" (one or two decimal digit) and "r", we delete characters.So with the string "451025478152r12r894251502300154r91r202"the final string I must have is "451025478152r12r894251502300154r91r" because the three last character are similar to "r" (one or two decimal digit) and "r".Thank you in advance Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 1, 2009 Moderators Share Posted February 1, 2009 So, I go resume.I have a string (in a tex file) similar to this string "451025478152r12r894251502300154r91r202"And I want read this file by starting of the end. And while three last character of the file are different of this regular expression ==> "r" (one or two decimal digit) and "r", we delete characters.So with the string "451025478152r12r894251502300154r91r202"the final string I must have is "451025478152r12r894251502300154r91r" because the three last character are similar to "r" (one or two decimal digit) and "r".Thank you in advanceDo not bump your posts within 24 hours of you last post period. Especially asking the same question that's already been answered, but you refuse to accept it. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts