aphesia Posted January 31, 2010 Share Posted January 31, 2010 hey guys, i´m currently making a program which should make it easier to upload at 1-click hosters but i cannot get this done: i have a .txt file with lots of links (each line = 1 link) now i want the script to read the last letters from each link (each line) and copy everything from the back of the link until the "/" comes. e.g. http://blabla.com/gtahatj15/file_name_here.exe now i want the script to copy "file_name_here.exe" and that for each line. i dont know how to tell the script that it should copy only the part after the last "/". thanks Link to comment Share on other sites More sharing options...
JohnOne Posted January 31, 2010 Share Posted January 31, 2010 (edited) Sounds like a job for StringRegExp() Unfortunately I am totally crap at creating patterns, maybe you will have more luck than I. EDIT: not be any good with patterns I would do something like this Assuming all the links are the same url $svar = FileReadLine("text.txt",1) If StringInStr($svar,"http://blabla.com/gtahatj15/") Then $var2 = StringReplace($var,"http://blabla.com/gtahatj15/","") Endif Obviously in some loop. Edited January 31, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted January 31, 2010 Share Posted January 31, 2010 (edited) I thought StringReg or StringRegExp would be needed, and one of those could probably be used, but since I'm in an 'array learning mode', I came up with this code. $var = "http://blabla.com/gtahatj15/file_name_here.exe" $array = StringSplit($var, "/") ConsoleWrite($array[$array[0]] & @LF) Edit: Deleted an unnecessary line Edited February 1, 2010 by snowmaker - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 31, 2010 Moderators Share Posted January 31, 2010 (edited) aphesia,Here is one that should work:$sURL = "http://blabla.com/gtahatj15/file_name_here.exe" Local $sFileName = StringRegExpReplace($sURL, "^.*\/", "") ConsoleWrite($sFileName & @CRLF)It translates as:^ - start at the beginning.* - as many characters as it takes\/ - find a / (you need to use the \ to escape the /)And because the basic rule is "greedy" (find as many as you can), the .* pattern runs until the final /Easy, n'est-ce pas? JohnOne,Do not give up so easily! Simple ones that (like this one that even I can manage) are the best place to start - just do not get too overawed by the real gurus who pop up here! There is a RegExp trainer somewhere round here which lets you play around with different patterns - I find it very useful.M23Edit: The trainer can be found here - have fun! Edited January 31, 2010 by Melba23 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...
JohnOne Posted January 31, 2010 Share Posted January 31, 2010 Thanks Melba23 I have not given up, I will get it in the end however long it takes, but I make a complete hash of it with the simplest strings most of the time, so wouldnt dare waste someones time with an effort. Thank you very kind for the link, I'l be checking it out forthwith. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted January 31, 2010 Share Posted January 31, 2010 It translates as: Edit: The trainer can be found here Thanks for including the 'translation', and the link to the SRETesterV2.1.au3 topic, that'll surely help when I think I get arrays and move onto SRE's.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
GEOSoft Posted January 31, 2010 Share Posted January 31, 2010 $sLink = "http://blabla.com/gtahatj15/file_name_here.exe" $sFile = StringRegExpReplace($sLink,"(?m:^).+/(.+), "$1") MsgBox(0, "Result", $sFile) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
GEOSoft Posted January 31, 2010 Share Posted January 31, 2010 RegEx is not needed here. Local $sLink = "http://blabla.com/gtahatj15/file_name_here.exe" Local $sFile = StringTrimLeft($sLink, StringInStr($sLink, "/", 0, -1)) MsgBox(0, "Result", $sFile) RegExp is not required in a lot of places but it comes in handy and it's fast. In your example I actually would have used StringMid() but that's just me. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
somdcomputerguy Posted February 1, 2010 Share Posted February 1, 2010 The _PathSplit UDF could've done it too. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
GEOSoft Posted February 1, 2010 Share Posted February 1, 2010 The _PathSplit UDF could've done it too. You don't even need the UDF, in fact I've never understood why we even have that function, perhaps just to confuse people. $spath = "C:\Some\Path\somefile.exe" $aPath = StringSplit($sPath, "\") $sFile = $aPath[Ubound($aPath) -1] MsgBox(0, "Result", $sFile) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
GEOSoft Posted February 1, 2010 Share Posted February 1, 2010 Yeah, there are actually a few ways to do it without RegEx. I think I remember reading here somewhere that RegEx is slower than the String Functions though.EDIT: Here's the topic I was thinking of. I suppose it may only apply to that specific situation though.http://www.autoitscript.com/forum/index.php?showtopic=108355At one time SREs were definitly slower than String functions but that isn't always the case now. I used that particular SRE in this case because I don't think the OP has related all the details as to what he wants to us just yet and If he wants what I think he does then it's a simple matter of changing the SREReplace to a simple SRE (using the same expression) to return an array. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Dr.Chi Posted November 18, 2011 Share Posted November 18, 2011 (edited) Drudging up old posts...Can someone help me though with Regex?I want the same solution, but this regex: "^.*/" Would not work for a URL like this:''https://web.company.com/Content/Tracking/PeopleReports/AsyncReportCreate.aspx?r=/Company/People%20Reports/Subscriber%20Most%20Recent%20Activity&HistoryAs it would go to the / after the page name.I have a lot of URLs like this and I really just want to strip the "page.aspx" out of it.Can someone help? This is for an Autoit script, but I'd prefer a regex statement in case I need to use it in Notepad++ or some other editor.Any help would be appreciated.EDIT: I think I could get it if I searched for the .aspx with a regex lookbehind argument using the W to select by words.... But that's as far as I get cause it's beyond my regex abilities. Edited November 18, 2011 by Dr.Chi Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 18, 2011 Moderators Share Posted November 18, 2011 Dr.Chi, This should do the trick: $sURL = "https://web.company.com/Content/Tracking/PeopleReports/AsyncReportCreate.aspx?r=/Company/People%20Reports/Subscriber%20Most%20Recent%20Activity&History" $sExtract = StringRegExpReplace($sURL, "(?i).*/(.*.aspx).*", "$1") MsgBox(0, "", $sExtract) (?i) - Case insensitive .*/ - As much as you can get until you find a / followed by (.*.aspx) - a number of character followed by .aspx - the brackets mean we capture this group .* - and then the rest of the string $1 - Replace it all with the captured group Because the matches are greedy by default, we find the final / just before the page name in the first section. Try it out and see if it works for you - although George will doubtless be along with a better one in a while if you want to wait! 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...
GEOSoft Posted November 18, 2011 Share Posted November 18, 2011 Nothing really wrong with that one although I would have used .+ inside the capture instead of .* and you don't have to escape "/" since it has no special meaning anyway. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 18, 2011 Moderators Share Posted November 18, 2011 George, Something of your tuition must be getting through then! 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...
Dr.Chi Posted November 18, 2011 Share Posted November 18, 2011 Thanks!!! Seriously, why do I even waste time searching the inter-tubes when all the Geniuses are right here on this forum? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 18, 2011 Moderators Share Posted November 18, 2011 Dr.Chi,I always recommend this site to anyone who want to learn about SREs. I hope it might be of use to you as well. 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...
Dr.Chi Posted November 18, 2011 Share Posted November 18, 2011 Thanks Melba23, that's a good resource. 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