czardas Posted March 20, 2013 Share Posted March 20, 2013 (?s) . the dot matches anything including new lines. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
PhoenixXL Posted March 20, 2013 Share Posted March 20, 2013 @WaterIt's called "lookbehind assertion" and can be found here.I guess we can't add quantifiers to a look-behind. Logic : The Regex doesn't know how many it has to go back to get the result. Hence the Look-Behind should be of a specific width or else it would fail at least in PCRE.@kylomasI don't get how the regexp deletes the entire lines containing the start and end delimiters. Can you explain? (and again...thank you for your patience...)Sure. Hold a while My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
water Posted March 20, 2013 Share Posted March 20, 2013 I have to admit that I didn't get it too. The term "lookbehind assertion" came to my mind because I once had a problem that was solved by another user wioth lookbehind assertion. The string processing I have to do can be done with the builtin functions of AutoIt. And it has the advantage that I can still read and understand my code in two years My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
kylomas Posted March 20, 2013 Share Posted March 20, 2013 @water - Shit, I thought I was the only one! Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
water Posted March 20, 2013 Share Posted March 20, 2013 I fear we are a huge community As soon as I find a lot of spare time (aka as soon as I have retired) I will try to understand regular expressions and might be able to leave this community My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
PhoenixXL Posted March 20, 2013 Share Posted March 20, 2013 (edited) Here it isLocal $sRead ;Through FileRead $sRead = "line 0 Something Here" & @CRLF & _ "line 1 this is the start" & @CRLF & _ "line 2 Another Line..." & @CRLF & _ "line 3 Some Other Data End after terminator token " & @CRLF & _ ; or $sRead = FileRead( "FileName.ext" ) "line 4 Some Other Data after deleted line" ; or $sRead = FileRead( "FileName.ext" ) Local $sText = StringRegExpReplace($sRead, "(?i)(.*?Start)(?s:.*?End)(.*\n)", '') MsgBox(64, "Return:", $sText) ; or FileWrite( "FileName.ext", $sText ) #cs - Pattern Decode - (?i) Make searches Case-Insensitive so that "Start" also matches "start". (.*?Start) | .*? - Match anything other than a line feed(\n) [lazy quantifier] | Start - Match the literal "Start" (?s:.*?End) | ?s: - Make this group non-capturing and activate (?s) modifier for this group only. | .*? - Match everything(including \n) [lazy quantifier] till the literal "End" (.*\n) | .* - Match anything that is not a line-feed | \n - Match the line-feed ( so that we don't get a blank line ). #ce -Pattern Decode - ;Finally replace everything matched to none..Please ask if you don't get anything As soon as I find a lot of spare time (aka as soon as I have retired) I will try to understand regular expressions and might be able to leave this communityIts very ease, literally. Only a little bit of practice is required. You can achieve it in a week. Regards Edited March 20, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
kylomas Posted March 20, 2013 Share Posted March 20, 2013 PhoenixXL, Why do you make the second group non-capturing? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
PhoenixXL Posted March 20, 2013 Share Posted March 20, 2013 (edited) We can easily add modifiers in a non-capturing group as you saw.Otherwise this would be the pattern with "On" and "Off" of the modifier(?i)(.*?Start)(?s)(.*?End)(?-s)(.*n)In a replace the non-capturing groups have the role only in back-referencing,and since here we don't require it, we no need to bother about the capturing and non-capturing groups Edited March 20, 2013 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
kylomas Posted March 20, 2013 Share Posted March 20, 2013 (edited) You can't do this: (?i)(.*?Start)(?s.*?End)(.*n) - making the '.' match anything for just that group? kylomas edit: jut tried it and it does not work but don't undertand why... Edited March 20, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
PhoenixXL Posted March 20, 2013 Share Posted March 20, 2013 Yes(?s.*?End) - here "." matches everything My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
FireFox Posted March 20, 2013 Share Posted March 20, 2013 Seems like the OP is already lost muttley no reply from him. Link to comment Share on other sites More sharing options...
BrewManNH Posted March 20, 2013 Share Posted March 20, 2013 @BrewmanNH there's errors in your last post.You were right, too much cutting and pasting. I have corrected it. 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 Link to comment Share on other sites More sharing options...
wisem2540 Posted March 20, 2013 Author Share Posted March 20, 2013 (edited) Seems like the OP is already lost muttley no reply from him. Well there is certainly more replies here than I expected. I was sleeping. So here is the one I chose to try. Local $sRead = FileRead( "FileName.txt" ) Local $sText = StringRegExpReplace($sRead, "(?i)(.*?Start)(?s:.*?End)(.*\n)", '') MsgBox(64, "Return:", $sText) ; or FileWrite( "FileName.ext", $sText ) I created a file, FileName.txt like this... no no no START delete delete delete END Ran the script and it did not work. I am looking through some other examples to see if I can figure out why. The msgbox comes up with the original txt file...nothing deleted Edited March 20, 2013 by wisem2540 Link to comment Share on other sites More sharing options...
wisem2540 Posted March 20, 2013 Author Share Posted March 20, 2013 expandcollapse popup#include #include Global $HostFile = "C:\WINDOWS\system32\drivers\etc\hosts" Local $OldHost If Not _FileReadToArray($HostFile, $OldHost) Then MsgBox(4096, "Error", " Error reading log to Array error:" & @error) Exit EndIf $index1 = _ArraySearch($OldHost, "plazaentries", 0, 0, 0, 1) $index2 = _ArraySearch($OldHost, "endplazaentries", 0, 0, 0, 1) If $index1 = -1 Then $plazaEntries = 0 If $index1 <> -1 Then $plazaEntries = 1 If $PlazaEntries = 0 Then Call ("NotFound") If $PlazaEntries = 1 Then Call ("Found") Func NotFound() MsgBox(0, "Error","No Plaza Entries Found...importing to end of file.") Local $NewHost = FileOpen($HostFile, 1) Local $ServerHosts If Not _FileReadToArray("ServerHosts.txt", $ServerHosts) Then MsgBox(4096, "Error", " Error reading log to Array error:" & @error) Exit EndIf ; Check if file opened for reading OK If $NewHost = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf For $x = 1 To $ServerHosts[0] FileWriteLine ($NewHost, $ServerHosts[$x]) Next EndFunc Func Found() MsgBox(0, "Info","Entries for plaza found in host file " & @CRLF & "Cleaning up") for $i = $index2 to $index1 Step -1 _ArrayDelete($OldHost, $i) next _FileWriteFromArray ($HostFile, $oldhost) EndFunc _ArrayDisplay ($oldhost) $Done = MsgBox(4, "Done", "Would you like to view the Host File?") If $Done = 6 Then Runwait ("Notepad.exe " & $Hostfile)Here is some code i got almost working last night. I know its a mess. The only thing that is puzzling, is that it will add a value at the top of the host file and I dont know why. Link to comment Share on other sites More sharing options...
wisem2540 Posted March 20, 2013 Author Share Posted March 20, 2013 (edited) Actually it looks like the value its putting at the top = the number of lines in the array. Is that normal? EDIT I changed my write line to _FileWriteFromArray ($HostFile, $oldhost, 1), to start at line1, and it seems to work. Edited March 20, 2013 by wisem2540 Link to comment Share on other sites More sharing options...
BrewManNH Posted March 20, 2013 Share Posted March 20, 2013 Is it putting that number in the file, or is it in the _ArrayDisplay, because if it's in the _ArrayDisplay, it's normal. Try using #requireadmin, you can't write to that file without having admin credentials (on Vista/7/8) 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 Link to comment Share on other sites More sharing options...
czardas Posted March 20, 2013 Share Posted March 20, 2013 You were right, too much cutting and pasting. I have corrected it.Easily done. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
PhoenixXL Posted March 20, 2013 Share Posted March 20, 2013 Ran the script and it did not work. I am looking through some other examples to see if I can figure out why.Some more to figure out. Can you please post the data of your file out here, so I could check why it didn't ran..Regards My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
wisem2540 Posted March 20, 2013 Author Share Posted March 20, 2013 (edited) Here ya go. Just change one to #START and the other to #END #PLAZAENTRIES 10.51.90.2 bjplaza01c01a.clin.bjc.org 10.51.90.3 bjplaza01c01b.clin.bjc.org 10.51.90.9 bjplaza01a01.clin.bjc.org 10.51.90.10 bjplaza01a02.clin.bjc.org 10.51.90.11 bjplaza01a03.clin.bjc.org 10.51.90.12 bjplaza01a04.clin.bjc.org 10.51.90.13 bjplaza01a05.clin.bjc.org 10.51.90.14 bjplaza01a06.clin.bjc.org 10.51.90.16 bjplaza01w01.clin.bjc.org 10.51.90.17 bjplaza01w02.clin.bjc.org 10.51.90.43 bjplaza01w03.clin.bjc.org 10.51.90.44 bjplaza01w04.clin.bjc.org 10.51.90.5 bjplazacsql.clin.bjc.org 10.51.90.4 bjplazacmgr.clin.bjc.org 10.51.90.7 OPENLink.clin.bjc.org 10.51.90.2 bjplaza01c01a 10.51.90.3 bjplaza01c01b 10.51.90.9 bjplaza01a01 10.51.90.10 bjplaza01a02 10.51.90.11 bjplaza01a03 10.51.90.12 bjplaza01a04 10.51.90.13 bjplaza01a05 10.51.90.14 bjplaza01a06 10.51.90.16 bjplaza01w01 10.51.90.17 bjplaza01w02 10.51.90.43 bjplaza01w03 10.51.90.44 bjplaza01w04 10.50.141.8 BJC_DR_ARCHIVE 10.51.90.5 bjplazacsql 10.51.90.4 bjplazacmgr 10.51.90.7 OPENLink 10.51.90.6 bjplzspan 10.40.8.7 bjris 10.33.162.2 bigben 10.33.162.32 relay1 10.35.141.213 mv301 10.35.141.212 gearviewqc #ENDPLAZAENTRIES Edited March 20, 2013 by wisem2540 Link to comment Share on other sites More sharing options...
wisem2540 Posted March 20, 2013 Author Share Posted March 20, 2013 (edited) Is it putting that number in the file, or is it in the _ArrayDisplay, because if it's in the _ArrayDisplay, it's normal.Try using #requireadmin, you can't write to that file without having admin credentials (on Vista/7/8)Good catch. I have made that adjustment and all is working with the above messy code I posted. Edited March 20, 2013 by wisem2540 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