LapidusCreatorium Posted September 21, 2008 Share Posted September 21, 2008 Hi, I have a problem for which I cannot find a solution as I am a beginner with autoit. There is a file where I need to replace a line based on a certain pattern. Here is my file content: prv("set_user_url","http://website.com/"); And my code: $find = 'prv("set_user_url","http://website.com/");' $replace = 'prv("set_user_url","http://new_website.com/");' $filename = "c:\app_folder\site_builder\cfg\usr.cfg" _ReplaceStringInFile($filename,$find,$replace) The problem is that the url of the user config needs to be changed and it is not the same on all users. So I need to use regex to find the url pattern in that file. The pattern I need to find is ((www\.|(http|https|ftp|news|file)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)]) How can I find the pattern and replace the line where it's found? Thank you. Link to comment Share on other sites More sharing options...
Community On Patrol Posted September 21, 2008 Share Posted September 21, 2008 Hi LapidusCreatoriu...,Just a note on Regular Expressions and AutoIt in case you didn't know.AutoIt uses the PCRE (Perl Compatible Regular Expressions) engine.If you are using google for tutorials or just searching for specifics, keep this in mind when looking for expressions or help on expressions.Some things that may help you along with future questions or concerns:QuickStartTutorialsRegExCoach Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted September 21, 2008 Author Share Posted September 21, 2008 Thank you for this automated reply, but I need some help on how to integrate them. Thank you. Link to comment Share on other sites More sharing options...
Andreik Posted September 21, 2008 Share Posted September 21, 2008 File contents are always a single line? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted September 21, 2008 Author Share Posted September 21, 2008 File contents are always a single line?No, they have up 100 lines depending on user configuration and settings.And I only need to find and replace that line. Link to comment Share on other sites More sharing options...
Andreik Posted September 21, 2008 Share Posted September 21, 2008 (edited) If is only line that beginning with prv("set_user_url", then this should work: #include <File.au3> $PATH = "c:\app_folder\site_builder\cfg\usr.cfg" $FILE = FileOpen($PATH,0) For $INDEX = 1 To _FileCountLines($PATH) $DATA = FileReadLine($FILE,$INDEX) If StringLeft($DATA,3) = 'prv("set_user_url",' Then _FileWriteToLine($PATH,$INDEX,"'" & $DATA & "'",1) EndIf Next FileClose($FILE) Edited September 21, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted September 21, 2008 Author Share Posted September 21, 2008 all lines start with prv. Would it better to identify the line by the start letters? For example to find it by prv("set_user_url" ? If so, how can I do it? Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted September 21, 2008 Author Share Posted September 21, 2008 OH. thank you for your code. I will test it, thanks. Link to comment Share on other sites More sharing options...
LapidusCreatorium Posted September 21, 2008 Author Share Posted September 21, 2008 Great. Code worked like a charm. Thank you very much. Link to comment Share on other sites More sharing options...
Andreik Posted September 21, 2008 Share Posted September 21, 2008 Great.Code worked like a charm.Thank you very much.You're welcome. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
trancexx Posted September 21, 2008 Share Posted September 21, 2008 Hi LapidusCreatoriu...,Just a note on Regular Expressions and AutoIt in case you didn't know.AutoIt uses the PCRE (Perl Compatible Regular Expressions) engine.If you are using google for tutorials or just searching for specifics, keep this in mind when looking for expressions or help on expressions.Some things that may help you along with future questions or concerns:QuickStartTutorialsRegExCoachThis could be the sign of artificial intelligence.In the Year of Darkness, 2029, the rulers of this planet devised the ultimate plan. They would reshape the Future by changing the Past. The plan required something that felt no pity. No pain. No fear. Something unstoppable. They created 'THE TERMINATOR'...I couldn't resist, sorry ♡♡♡ . eMyvnE 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