AnarchOi Posted September 22, 2009 Share Posted September 22, 2009 $variable = "http://www.autoitscript.com/forum/index.php" how can i remove everything before the LAST " / " ? Then show the result in a MsgBox Using my example, the result would be "index.php" thanks! http://www.anarcho-punk.net Link to comment Share on other sites More sharing options...
jvanegmond Posted September 22, 2009 Share Posted September 22, 2009 $variable = "http://www.autoitscript.com/forum/index.php" $n = StringInStr($variable, "/", 0, -1) $result = StringTrimLeft($variable, $n) ConsoleWrite("Without regex: " & $result & @CRLF) $result = StringRegExp($variable, ".*/(.*)", 3) $result = $result[0] ConsoleWrite("With regex: " & $result & @CRLF) github.com/jvanegmond Link to comment Share on other sites More sharing options...
AnarchOi Posted September 22, 2009 Author Share Posted September 22, 2009 thanks! http://www.anarcho-punk.net Link to comment Share on other sites More sharing options...
jvanegmond Posted September 22, 2009 Share Posted September 22, 2009 You're welcome. github.com/jvanegmond Link to comment Share on other sites More sharing options...
AnarchOi Posted September 22, 2009 Author Share Posted September 22, 2009 Hello, just one more question: Taking the code, how can i also remove everything after the LAST dot the result would be "index" Thanks again! http://www.anarcho-punk.net Link to comment Share on other sites More sharing options...
jvanegmond Posted September 22, 2009 Share Posted September 22, 2009 You can try learning by example. $variable = "http://www.autoitscript.com/forum/index.php" $n = StringInStr($variable, "/", 0, -1) $result = StringTrimLeft($variable, $n) $n = StringInStr($result, ".") $result = StringLeft($result, $n-1) ConsoleWrite("Without regex: " & $result & @CRLF) $result = StringRegExp($variable, ".*/(.*)\.", 3) $result = $result[0] ConsoleWrite("With regex: " & $result & @CRLF) github.com/jvanegmond Link to comment Share on other sites More sharing options...
AnarchOi Posted September 22, 2009 Author Share Posted September 22, 2009 Last question, i promise ^^I want to use a similar code in another script, but on a list of URLs and not only just 1the list looks like thishttp://www.server.com/file.phphttp://www.anotherserver.com/anotherfile.phphttp://www.hello.com/goodbye.html(each URL is on a new line)I want to delete everything before the last " / " on each linethe result would be:file.phpanotherfile.phpgoodbye.htmlThanks again for your help, this script is going to save me hours and hourss of work http://www.anarcho-punk.net Link to comment Share on other sites More sharing options...
Paulie Posted September 22, 2009 Share Posted September 22, 2009 I think Manadar has given you plenty of help as it is. Perhaps you should read the helpfile. Search for things like Array, Loop, and maybe FileRead Link to comment Share on other sites More sharing options...
AnarchOi Posted September 22, 2009 Author Share Posted September 22, 2009 (edited) I have already read the regex help page, i'm really a newbie especially with regex... I have tryed many different things but i can't come to something that works... I even tryed to search the forums and google to see if i could find a forum post answering my question... Edited September 22, 2009 by AnarchOi http://www.anarcho-punk.net Link to comment Share on other sites More sharing options...
Paulie Posted September 22, 2009 Share Posted September 22, 2009 Manadar has provided you with a working example of regex that will do what you want. You are asking how to do it to multiple items. That answer is all over the helpfile and forums. I'll even give you a big hint. Try _FileReadToArray() in the index of the helpfile Link to comment Share on other sites More sharing options...
AnarchOi Posted September 22, 2009 Author Share Posted September 22, 2009 I just read the help page on FileReadToArray, but now i am even more confused... i don't want to read a file then sort the content to an array (this is what this function will do if i understood correctly??), the string that needs replacement is already stored in $variable $variable = "http://www.server.com/file.php http://www.anotherserver.com/anotherfile.php http://www.hello.com/goodbye.html" i want to change it to $variable = "file.php anotherfile.php goodbye.html" http://www.anarcho-punk.net Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 23, 2009 Moderators Share Posted September 23, 2009 _URLSplit 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...
Malkey Posted September 23, 2009 Share Posted September 23, 2009 .... the string that needs replacement is already stored in $variable $variable = "http://www.server.com/file.php http://www.anotherserver.com/anotherfile.php http://www.hello.com/goodbye.html" i want to change it to $variable = "file.php anotherfile.php goodbye.html" Try this. ; Local $variable = "http://www.server.com/file.php" & @CRLF & _ "http://www.anotherserver.com/anotherfile.php" & @CRLF & _ "http://www.hello.com/goodbye.html" & @CRLF Local $sUrl, $sOldVariable = $variable, $sRes = "" For $i = 1 To 3 $sUrl = StringRegExpReplace($variable, "^(.*\v+?|$){" & $i & "}(?s).*", "\1") ; Return line no. 1-based $sRes &= StringRegExpReplace($sUrl, '^(?s)(?i)(http|ftp|https|file)://(.*?/|.*$)(.*/){0,}(.*), "\4") Next $variable = $sRes MsgBox(0, 'New Contents of "$variable"', "$variable = " & $sOldVariable & @CRLF & "changed to" & @CRLF & @CRLF & "$variable = " & $variable) ; Link to comment Share on other sites More sharing options...
jvanegmond Posted September 23, 2009 Share Posted September 23, 2009 This is stupid. He just keeps asking until someone writes this simple stuff for him.. Thanks for standing up, Paulie. github.com/jvanegmond Link to comment Share on other sites More sharing options...
AnarchOi Posted September 23, 2009 Author Share Posted September 23, 2009 (edited) Yeah right, this is stupid. Fuck this, i'm just going to stop posting... I didn't want to get insulted or bother anyone... It might sound like i'm just begging for codes but i am asking precise questions because i know what i need. And all parts of code that was given to me on this forum were very helpful and i have used it in multiple codes. It's not just copy and paste, after using it one time i understand how it works and i can modify it to suit my needs. I asked a couple of questions since 2 days on this forum, and so far my script have 300 lines of codes.... (i can post if you want, you will see by yourself it's not only copy and paste)... Oh yeah, i guess i just "kept asking until someone answers" to make all this script... I thought this was a HELP forum. Like i said i have tryed searching by myself before posting. I have read the manual, searched google, browsed the forums.... It's not my fault if i'm a newbie. I was at this level when i coded PHP and now i can make my own script. The problem when you start with a new coding language is just to find the precise functions you are looking for and how to properly use them. I thought this forum was for newbies too. Thanks anyway, but seeing how i'm getting treated i will find a solution myself Edited September 23, 2009 by AnarchOi http://www.anarcho-punk.net Link to comment Share on other sites More sharing options...
jvanegmond Posted September 23, 2009 Share Posted September 23, 2009 Wow. There's no need to get pissed about this. We did help you and answered all your questions to the best of our abilities, and everything.I'll try and explain this from our point of view, because you clearly don't understand it.It might sound like i'm just begging for codes but i am asking precise questions because i know what i need. And all parts of code that was given to me on this forum were very helpful and i have used it in multiple codes. It's not just copy and paste, after using it one time i understand how it works and i can modify it to suit my needs.If this was true, then you would only need one or two RegEx examples.I have showed you to modify this URL (http://www.aweb.com/index.php) into:index.php (Pattern: .*/(.*) )and into:index (Pattern: .*/(.*)\. )See how similar those patterns are? One just has a dot on the end, which means we tell it to stop before the dot. That seems pretty trivial to me. Now I understand you may not get this the first time (took me months of reading and trying to learn regular expressions). That's why I also provided the code to do it with regular string operations. I've used normal string operations for years before I finally understood regular expressions.Then you come barging in, demanding to be shown regular expressions for your application without showing what you've tried or showing at all that you've put effort into this. Can you imagine how I felt? I needed to learn all this stuff too before I could use it in my projects, so that means that so should you. Or at least make a good effort!Even your last question was answered by Malkey, and then you make a big post about how we're not treating you delicately enough, that you expected to be treated like a king if you ask a question. This is a free help and support forum, so if multiple members feel that you're doing something wrong; You're doing something wrong. github.com/jvanegmond 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