Zomp Posted April 1, 2008 Share Posted April 1, 2008 Consider the following text: 1 2 3 How can I trasform it to: 1 3 ? I've tried with the following code $s1="1" & @crlf & "2" & @crlf & "3" & @crlf msgbox(0,"",$s1) $s2=StringRegExpReplace ( $s1, "(?s)*?2\r\n(?s)*?", "\0\1") msgbox(0,"",$s2) but without success. Where is my mistake? Many thanks for your help. Link to comment Share on other sites More sharing options...
weaponx Posted April 1, 2008 Share Posted April 1, 2008 You should provide a better example text because I could give you an expression that only extracts the first and last character. Are you wanting the entire first line and the entire last line? Link to comment Share on other sites More sharing options...
Malkey Posted April 1, 2008 Share Posted April 1, 2008 Try $s1="1" & @crlf & "2" & @crlf & "3" & @crlf msgbox(0,"",$s1) $s2=StringRegExpReplace ( $s1, @crlf & "2" , "") msgbox(0,"",$s2) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 1, 2008 Moderators Share Posted April 1, 2008 (edited) You should provide a better example text because I could give you an expression that only extracts the first and last character. Are you wanting the entire first line and the entire last line?I agree... this could really get blown out of proportion.a simple expression : ( $s1, "\r\n2\r\n", @CRLF) would do what you are looking for, but there is always more to the story then what most say in their initial post... and I'd be willing to bet this would not suit your specific needs.Might be easier to just split the string into an array and remove the specific lines you want. Edited April 1, 2008 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...
Zomp Posted April 2, 2008 Author Share Posted April 2, 2008 (edited) You should provide a better example text because I could give you an expression that only extracts the first and last character. Are you wanting the entire first line and the entire last line?Yes, you are right. I apologize.Suppose I have a text file of several lines and I know that on a line (whose position I do not know) it is written "2" followed by CRLF. Then I want to obtain the same text file but without that line.I hope to has been enough clear. Thanks for your patience. Edited April 2, 2008 by Zomp Link to comment Share on other sites More sharing options...
/dev/null Posted April 2, 2008 Share Posted April 2, 2008 Yes, you are right. I apologize.Suppose I have a text file of several lines and I know that on a line (whose position I do not know) it is written "2" followed by CRLF. Then I want to obtain the same text file but without that line.I hope to has been enough clear. Thanks for your patience.Hm.. a regular expression for that? Why not:_FileReadToArray()a for loop with FileWriteLine(). Write everything EXCEPT the unwanted lineCheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Zomp Posted April 2, 2008 Author Share Posted April 2, 2008 (edited) Hm.. a regular expression for that? Why not:_FileReadToArray()a for loop with FileWriteLine(). Write everything EXCEPT the unwanted lineCheersKurtFrom my newbie point of view, it seems that your method is much slower than using a single regular expression.Am I wrong? Edited April 2, 2008 by Zomp Link to comment Share on other sites More sharing options...
/dev/null Posted April 2, 2008 Share Posted April 2, 2008 (edited) From my newbie point of view, it seems that your method is much slower than using a single regular expression.Am I wrong?it depends on your regular expression and the size of the file. However, as reading and writing the filetakes ~95% of the time anyway, I don't see a big difference (real life not academic). Clear and easy to understand code is worth much more than a few milliseconds run time.CheersKurt Edited April 2, 2008 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Zomp Posted April 2, 2008 Author Share Posted April 2, 2008 (edited) it depends on your regular expression and the size of the file. However, as reading and writing the filetakes ~95% of the time anyway, I don't see a big difference (real life not academic). Clear and easy to understand code is worth much more than a few milliseconds run time.CheersKurtSo, if I have well understood, there is a negligible difference between a single filewrite instruction and a loop of filewriteline instructions, the global length of the string being equal. Happy to have learned the lesson. Edited April 2, 2008 by Zomp Link to comment Share on other sites More sharing options...
/dev/null Posted April 2, 2008 Share Posted April 2, 2008 So, if I have well understood, there is a negligible difference between a single filewrite instruction and a loop of filewriteline instructions, the global length of the string being equal. Happy to have learned the lesson.well, that's not the full truth as well. It heavily depends on the other activities of your system. If you read/write a lot of data while you run the script, it will certainly have a larger impact than if the system is idle (reason: disk head moves). __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
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