Coded4Decades Posted March 22, 2014 Posted March 22, 2014 How can I delete lines using Find and replace? Here are two examples of what I want to do. Example 1: To improve readability, I often put 5 or more blank lines before and after chunks of particulary difficult code. Before I put the program into production, I want replace 2 or more consecutive blank lines with a single blank line. How do I do this? Example 2: To debug a program I inserted hundreds of debugging lines. The program now looks like this $a = $b $x = $y Logwrite ("debug info" & $x) $c = $d Logwrite ("debug info" & other junk) etc etc for about 1000 lines. The program now works, so I want to remove the LogWrite lines. I tried using find and replace with regular expressions to DELETE the lines with this pattern. ^logwrite(.*$ But, that only BLANKED the lines, it did not delete them. I also failed with variations of ^logwrite(.*[n]$ And, I tried "transform backslash characters" but that did not help. Help ! Bob
BrewManNH Posted March 22, 2014 Posted March 22, 2014 SciTE's find and find & replace can use a RegEx in the search parameters and references in the replace parameters. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Moderators Melba23 Posted March 22, 2014 Moderators Posted March 22, 2014 Coded4Decades,I have never found SciTE's RegEx replace to be very good - something their developers could improve a lot in my opinion. I would just write another script to do the job for you - that is what Autoit is good at. $sScript = FileRead("OrgScript.au3") $sNewScript = StringRegExpReplace($sScript, "Logwrite.*($|\R)", "") FileWrite("NewScript.au3", $sNewScript)Something along those lines works for me. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
BrewManNH Posted March 22, 2014 Posted March 22, 2014 I just reread the Regex information for SciTE and it wouldn't work anyways, as it can't find CR or LF because it only searches line by line and not the whole text. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Developers Solution Jos Posted March 22, 2014 Developers Solution Posted March 22, 2014 The n is not supported in SciTE as indicated in the FAQ. Only option I can think of is to do it in 2 steps: Replace the text in your regex with something static/unique: Replace the new Static text with Transform selected: Cheers Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
BrewManNH Posted March 22, 2014 Posted March 22, 2014 This LUA script will replace multiple blank lines with a single blank line and it will leave single blank lines as-is. function del_empty_lines() local txt = editor:GetText() if #txt == 0 then return end local chg, n = false while true do txt, n = string.gsub(txt, "(\r?\n\r?\n)%s*\r?\n", "%1") if n == 0 then break end chg = true end if chg then editor:SetText(txt) editor:GotoPos(0) end end I added this to the Tools.lua file in SciTE, and added the following to the SciteUser.properties file so I can call it using a right click menu in SciTE. # 46 Remove Empty Lines # command.name.46.*=Remove Empty Lines command.46.*=del_empty_lines command.subsystem.46.*=3 user.context.menu=||Add as Snippet|1116|Remove Empty Lines|1146| You can uncomment the second line of the above to add the tool to the Tools menu in Scite, and/or comment out/remove the last line to take it off of the right click menu. The LUA script was found here. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
JohnOne Posted March 22, 2014 Posted March 22, 2014 I done the same as the OP a few years ago, as soon as I had, my script went to crap and I needed them back. Next time I just left them and replaced "Mydebugfunc(...)" with "; Mydebugfunc(...)" to comment them out. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Coded4Decades Posted March 22, 2014 Author Posted March 22, 2014 (edited) all good suggestions. The one I use was Jos's two step approach which worked great for Example #2. For example #1 I only needed a one step to change all groups of consecutive blank lines into a single blank line: I simply changed rnrnrn to rnrn and repeated the find until there were no more replacements. Thank for your help, that was driving me crazy. Edited March 22, 2014 by Coded4Decades
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