Jump to content

copy part of the link from .txt


aphesia
 Share

Recommended Posts

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 :D

Link to comment
Share on other sites

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 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

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 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

  • Moderators

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? :D

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.

M23

Edit: The trainer can be found here - have fun! :huggles:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

$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

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

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

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=108355

At 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

  • 1 year later...

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&History

As 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 by Dr.Chi
Link to comment
Share on other sites

  • Moderators

Dr.Chi,

This should do the trick: :D

$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. :rip:

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! :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

George,

Something of your tuition must be getting through then! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...