StArL0rd84 wrote: ↑October 9th, 2020, 6:48 pm
I am making a launcher and I have made a measure that grabs the name from the exe or folder, but i also want to add websites and automatically grab the name from URL's too.
I know very little about how the RegExpSubstitute in the code below works, not enough to possibly add this function.
So my question finally Is...
Is it possible to form a RegExpSubstitute that also removes everything from a URL but the name of the website?
Very few things (if any) are impossible, but it's true that this, although a very good question, is a tricky one. Tricky because the local path syntax and the URI
syntax, while somewhat similar, are also different in terms of structure and characters acting as delimiters (simple example: the #
character marks the beginning of a fragment in the URI, so a part that you wouldn't want to include in the host name result if they are adjacent, e.g. www.Rainmeter#Top
, yet is a perfectly valid character to be included in a file name, e.g. C:\Rainmeter#2.exe
; fortunately some of these cases are rare and URIs like www.rainmeter.net#Top
work). That being said, I think the regex below is a decent attempt to solve the issue:
Code: Select all
Text="Text = [#String[#StringIndex]]#CRLF#Name = %1"
LeftMouseUpAction=[!SetVariable StringIndex ((#StringIndex#+1)%#StringCount#)][!UpdateMeasure FileOrHostName][!UpdateMeter Result][!Redraw]
Click on the skin to iterate through the test strings and see if the expected result is provided. As far as I could understand your question, it does - bar the relatively unlikely case of an URI having an IP as its host name, e.g. 220.127.116.11
. While such a case can be handled, it doesn't suit well with the file name extraction from a local path in the same substitute, due to the presence of multiple period (.
) characters. But then, that's just one case where it doesn't quite grab what it should, and a pretty fringe case too.