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.
url.png
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
[Variables]
StringCount=10
StringIndex=0
String0=C:\Forum\Stuff.net\hello@Rainmeter.exe
String1=C:\Forum\Stuff.net\Rainmeter.exe
String2=C:\Forum\Stuff.net\Rainmeter#2.exe
String3=https://forum.rainmeter.net/viewtopic.php?f=5&t=36150
String4=https://forum.something.rainmeter.net/viewtopic.php?f=5&t=36150
String5=https://viewtopic.php?f=5&t=36150
String6=scheme://username:password@host.domain:port/path?query#fragment
String7=scheme://username:password@other.host.domain:port/path?query#fragment
String8=scheme://username:password@168.246.2.15:port/pathpart1/pathpart2/pathpart3?query#fragment
String9=https://api.weather.com/v3/aggcommon/v3-wx-observations-current;v3-wx-forecast-daily-15day?format=json&geocode=26.38,49.50&units=m&apiKey=100
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255
---Measures---
[Iterator]
Measure=Calc
Formula=((Iterator+1)%#StringCount#)
UpdateDivider=-1
[FileOrHostName]
Measure=String
String="[#String[#StringIndex]]"
UpdateDivider=-1
RegExpSubstitute=1
Substitute="(?<!\/|\\)(?::|\/|\?)(?!\/|\\)[^:]*?$":"","^.*(?::.*?@|\\|\/)(?=.*\..*)":"",".*\.(?=.*?\..*?)":"","\..*?$":""
DynamicVariables=1
---Meters---
[Result]
Meter=STRING
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=10
AntiAlias=1
MeasureName=FileOrHostName
Text="Text = [#String[#StringIndex]]#CRLF#Name = %1"
LeftMouseUpAction=[!SetVariable StringIndex ((#StringIndex#+1)%#StringCount#)][!UpdateMeasure FileOrHostName][!UpdateMeter Result][!Redraw]
DynamicVariables=1
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.
168.246.2.15. 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.