It is currently April 26th, 2024, 8:30 pm

Another regexp question - how to get the folder name in a path?

Get help with creating, editing & fixing problems with skins
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Another regexp question - how to get the folder name in a path?

Post by CodeCode »

balala wrote: August 28th, 2022, 7:48 pm Sorry I thought you'll use the substitution ONLY for paths of files. My bad...
But now I'm not sure. For files I think my susbtitution does work. But what should it return for instance for the H:\Movies\TV Shows\ path? Sorry, but I didn't understand (my bad again)...
"TV Shows\"

:thumbup:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Another regexp question - how to get the folder name in a path?

Post by CodeCode »

The ini is also encoded with UTF-16 LE with Bom
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
tass_co
Posts: 518
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

Re: Another regexp question - how to get the folder name in a path?

Post by tass_co »

CodeCode wrote: August 28th, 2022, 8:07 pm The ini is also encoded with UTF-16 LE with Bom

Code: Select all

Substitute="^.*\\(.*)(.).*":"\1\2"
Untitled.png
I didn't see the last "\" in the address.
It was my fault. I'm sorry for the confusion :oops:
You do not have the required permissions to view the files attached to this post.
I don't know where i going from here, but i promise it won't be boring... :great:
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Another regexp question - how to get the folder name in a path?

Post by balala »

CodeCode wrote: August 28th, 2022, 8:00 pm "TV Shows\"

:thumbup:
I think you have to use a two step substitution. In the first step you'll remove the last backslash (if there is any). In the second substitution, you get the needed part of the path and add back the backslash (if you want). Try this option please: Substitute="^(.*)\\$":"\1","^(.*)\\(.*)$":"\2\" (see below why is colored red the last backslash).
As you probably figured it out, the first substitution ("^(.*)\\$":"\1") is executed only if the path ends with a backslash. In this case, that last backslash is removed.
The second substitution ("^(.*)\\(.*)$":"\2\") returns the needed folder name and adds back the backslash. If you want not to add the last backslash, just remove the last character of the substitution (the red colored above).
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Another regexp question - how to get the folder name in a path?

Post by CodeCode »

Hey guys.
Sorry to present a frustratingly weird issue.

I seem to have found the solution, for me.

Substitute="^.*\\(.*)\\.*$":"\1\"

Now I am worried that this is a local issue with me, and the regexp will not work for other people.

Can you please test my solution?
Capture.PNG
You do not have the required permissions to view the files attached to this post.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
tass_co
Posts: 518
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

Re: Another regexp question - how to get the folder name in a path?

Post by tass_co »

CodeCode wrote: August 28th, 2022, 8:25 pm Hey guys.
Sorry to present a frustratingly weird issue.

I seem to have found the solution, for me.

Substitute="^.*\\(.*)\\.*$":"\1\"

Now I am worried that this is a local issue with me, and the regexp will not work for other people.

Can you please test my solution?
Capture.PNG
right, works fine

Code: Select all

Substitute="^(.*)\\$":"\1", "^(.*)\\(.*)$":"\2\" ;<=== balala
Substitute="^.*\\(.*)\\.*$":"\1\" ;<=== you
Substitute="^.*\\(.*)(.).*":"\1\2" ;<=== me
I don't know where i going from here, but i promise it won't be boring... :great:
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Another regexp question - how to get the folder name in a path?

Post by CodeCode »

tass_co wrote: August 28th, 2022, 8:33 pm right, works fine

Code: Select all

Substitute="^(.*)\\$":"\1", "^(.*)\\(.*)$":"\2\" ;<=== balala
Substitute="^.*\\(.*)\\.*$":"\1\" ;<=== you
Substitute="^.*\\(.*)(.).*":"\1\2" ;<=== me
That is crazy!!
They all work.
Too cool... :rolmfao:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Another regexp question - how to get the folder name in a path?

Post by balala »

CodeCode wrote: August 28th, 2022, 8:25 pm Now I am worried that this is a local issue with me, and the regexp will not work for other people.
One thing I have to add. The above substitution returns the name of the last folder in the path, if the path ends with a backslash, but returns the previous folder, if the path doesn't contain a backslash at the end. I tried to write my solution to work and return the last element in both cases. Definitely your solution is shorter, but are you absolutely positive there is no case when the last backslash is missing?
For instance for the H:\Movies\TV Shows\ path your solution returns TV Shows\, but for H:\Movies\TV Shows (no ending backslash), it returns Movies\
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Another regexp question - how to get the folder name in a path?

Post by CodeCode »

balala wrote: August 28th, 2022, 8:53 pm One thing I have to add. The above substitution returns the name of the last folder in the path, if the path ends with a backslash, but returns the previous folder, if the path doesn't contain a backslash at the end. I tried to write my solution to work and return the last element in both cases. Definitely your solution is shorter, but are you absolutely positive there is no case when the last backslash is missing?
For instance for the H:\Movies\TV Shows\ path your solution returns TV Shows\, but for H:\Movies\TV Shows (no ending backslash), it returns Movies\
Wow! Now that is awesome! Thanks for helping so much. In my view, balala's solution is the most versatile - since it allows for no backslash, yet provides it in the returned output.

Perfecto! :thumbup:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Another regexp question - how to get the folder name in a path?

Post by balala »

CodeCode wrote: August 28th, 2022, 8:58 pm Wow! Now that is awesome! Thanks for helping so much. In my view, balala's solution is the most versatile - since it allows for no backslash, yet provides it in the returned output.

Perfecto! :thumbup:
Great! I'm glad. :great: