Sam137 Posted November 15, 2011 Share Posted November 15, 2011 (edited) Hi Guys Can you please help me out with the pattern of the one which is below: Pattern to look: "filepath = " There are 16 spaces between "filepath" and "= " If StringRegExp($sStr, "(?im)^(filepathh*=h*[^v]+)") Then $sNewStr = StringRegExpReplace($sStr, "(?im)^(filepath)(h*=h*)([^v]+)", "$1$2" & _ StringRegExpReplace("C:Multi DDt Delete Encounter MPIcleanup.in", "()", "")) $sStr is the file which is returned from the Fileread command. I Just want to know how the code the pattern. Edited November 15, 2011 by Sam137 Link to comment Share on other sites More sharing options...
funkey Posted November 15, 2011 Share Posted November 15, 2011 Do you know "StringStripWS()"? Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
jchd Posted November 15, 2011 Share Posted November 15, 2011 StringStripWS will remove WS from inside the path as well, I'm afraid. @Sam137, What does you input exactly look like and what do you expect as output, precisely? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Sam137 Posted November 15, 2011 Author Share Posted November 15, 2011 Okay well,I am searching for the below string in the file."filepath****************= "If this is found then i want to replace it with:"filepath****************= C:Multi DDt Delete Encounter MPIcleanup.in" NOTE: Please consider all * as spaces. For that i have the below coding. But its not working.If StringRegExp($sStr, "(?im)^(filepathh*=h*[^v]+)") Then $sNewStr = StringRegExpReplace($sStr, "(?im)^(filepath)(h*=h*)([^v]+)", "$1$2" & _ StringRegExpReplace("C:Multi DDt Delete Encounter MPIcleanup.in", "()", "")) Link to comment Share on other sites More sharing options...
funkey Posted November 15, 2011 Share Posted November 15, 2011 OK, and why not use StringReplace only? Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Sam137 Posted November 15, 2011 Author Share Posted November 15, 2011 Well I can use String Replace, but the problem is :Actual whole string in the file is: "filepath****************= e:autitMulti Encounter MPIcleanup.in"First thing i want to search for the string:"filepath****************= " Remember * as spaces and then i delete the remaining part of the string i.e."e:autitMulti Encounter MPIcleanup.in" then i replace with "filepath****************= C:Multi DDt Delete Encounter MPIcleanup.in". I think it will be a tedious job in string Replace. Any suggestions? Link to comment Share on other sites More sharing options...
funkey Posted November 15, 2011 Share Posted November 15, 2011 Maybe I don't understand your problem right, but why not StringReplace($sStr, "e:autitMulti Encounter MPIcleanup.in", "C:Multi DDt Delete Encounter MPIcleanup.in") ?? Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Sam137 Posted November 15, 2011 Author Share Posted November 15, 2011 "e:autitMulti Encounter MPIcleanup.in" is not consistent with all the files it keeps on changing, the only thing which is consistent is : "filepath****************=" Link to comment Share on other sites More sharing options...
kylomas Posted November 15, 2011 Share Posted November 15, 2011 (edited) sam137, You are not defining your requirements logically or consistently. Give an example of 10+ filenames and what you need to change them to. kylomas Edit: spelling Edited November 15, 2011 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...
Sam137 Posted November 15, 2011 Author Share Posted November 15, 2011 Ok, my requirement is:I have a folder which contains 'n' number of files. I want to open the first file and search for the string "filepath****************= " Remember * as spaces and then i delete the remaining part of the string i.e."e:\autitMulti\ Encounter MPI\cleanup.in" , after deleting the second fragment we have only left with "filepath****************= " then i replace with "filepath****************= C:\Multi DDt Delete Encounter MPI\cleanup.in".See an example of the file in the attachment.Example.txt Link to comment Share on other sites More sharing options...
jchd Posted November 15, 2011 Share Posted November 15, 2011 Does this work as you expect? Local $text = FileRead("Example.txt") Local $newtext = StringRegExpReplace($text, "(?im)(^s*filepath[^=]*=)(.*)", "$1C:Multi DDt Delete Encounter MPIcleanup.in") ConsoleWrite($newtext & @LF) Local $hdl = FileOpen("Changed.txt", 2) FileWrite($hdl, $newtext) FileClose($hdl) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Zedna Posted November 16, 2011 Share Posted November 16, 2011 I tried code from jchd and I discovered it needs doubled to work correctly: Local $newtext = StringRegExpReplace($text, "(?im)(^s*filepath[^=]*=)(.*)", "$1C:Multi DDt Delete Encounter MPIcleanup.in") Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Malkey Posted November 16, 2011 Share Posted November 16, 2011 I believe the script in post #1 works perfectly.If the file being read (with FileRead()) is not in the same directory or folder as the script that you are using then the full path of the file to be read (or a path relative to the script) should be used in the FileRead() function.Because I had the test ".in" file in the same directory as the script this has always worked for me.See the modified script see if the results returned are as per your requirements. Link to comment Share on other sites More sharing options...
jchd Posted November 16, 2011 Share Posted November 16, 2011 @Zedna Sure backslashes need doubling there (reference to captured groups may use $1 or 1 syntax.) They're doubled in my copy. I don't get it how they got de-doubled magically during copy/paste. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 16, 2011 Moderators Share Posted November 16, 2011 jchd,It is this wonderful "upgraded" editor we now have. I use it in basic mode all the time - the WYSIWYG version is just too flaky. 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 Link to comment Share on other sites More sharing options...
jchd Posted November 16, 2011 Share Posted November 16, 2011 Oh shitty modernity. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Sam137 Posted November 16, 2011 Author Share Posted November 16, 2011 @jchd - Thanks for the help.I like to get the information how to modify it when i have a 2 or more strings to seach and replace with another.Currently what i have given is to search only for "filepath****************= ". Now i have more strings to search for example "logpath****************= " and "errorpath****************= ". The problem is I dont have a starndard replacement string for all the three.In one single file:"filepath****************= " has to be replaced by "C:Multi DDt Delete Encounter MPIcleanup.in""logpath****************= " has to be replaced by "D:Testtestup.in""errorpath****************= " has to be replaced by "E: Encounter MPItesting.in" how can i change the below string to cater this.Local $newtext = StringRegExpReplace($text, "(?im)(^s*filepath[^=]*=)(.*)", "$1C:Multi DDt Delete Encounter MPIcleanup.in") Link to comment Share on other sites More sharing options...
funkey Posted November 16, 2011 Share Posted November 16, 2011 Last try from my side: #Include <File.au3> Global $aFile _FileReadToArray("Example.txt", $aFile) For $i = 1 To $aFile[0] If StringInStr($aFile[$i], "filepath****************=") Then $aFile[$i] = "filepath****************= C:Multi DDt Delete Encounter MPIcleanup.in" If StringInStr($aFile[$i], "logpath****************=") Then $aFile[$i] = "logpath****************= D:Testtestup.in" If StringInStr($aFile[$i], "errorpath****************=") Then $aFile[$i] = "errorpath****************= E: Encounter MPItesting.in" Next _FileWriteFromArray("Example_new.txt", $aFile, 1) Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Sam137 Posted November 16, 2011 Author Share Posted November 16, 2011 But the alignment is getting changed. Its going to the first position. I would want something like in the attacheed file.Example.txt Link to comment Share on other sites More sharing options...
BrewManNH Posted November 17, 2011 Share Posted November 17, 2011 That's a standard ini file, are you absolutely 100% sure you need the spaces to remain in the file when it's read by whatever needs to read that file? If not, you can probably just use Iniwrite to rewrite those values, and you won't need any regexp to do it. You might even be able to do it with the spacing, but I don't guarantee that it will keep the spacing. 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...
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