It is currently April 18th, 2024, 9:27 pm

(solved) Need some help with regex

Get help with creating, editing & fixing problems with skins
User avatar
alexks_101
Posts: 4
Joined: August 2nd, 2018, 10:26 am
Location: Corsica

(solved) Need some help with regex

Post by alexks_101 »

Hello, I'm finally updating my own custom skins created 3 years ago :D

I'm adding some HWinfo stuff but I'm struggling with regex.
Tried several things, but I can't get rid of this:

Code: Select all

 (MS-7A34) (Nuvoton NCT6795D)
It's for my motherboard name which is "MSI B350 PC MATE (MS-7A34) (Nuvoton NCT6795D)".

I'm pretty sure you guys will answer "oh that's obvious, just put <snippet>" :D

Thanks!
Last edited by alexks_101 on August 2nd, 2018, 12:44 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Need some help with regex

Post by balala »

Me at least, didn't understand what is the question. Some details would be great.
User avatar
alexks_101
Posts: 4
Joined: August 2nd, 2018, 10:26 am
Location: Corsica

Re: Need some help with regex

Post by alexks_101 »

What I mean is that instead of "MSI B350 PC MATE (MS-7A34) (Nuvoton NCT6795D)" for the motherboard name I just want "MSI B350 PC MATE", using a regex substitution. This stuff is displayed with HWinfo plugin.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Need some help with regex

Post by balala »

alexks_101 wrote:What I mean is that instead of "MSI B350 PC MATE (MS-7A34) (Nuvoton NCT6795D)" for the motherboard name I just want "MSI B350 PC MATE", using a regex substitution. This stuff is displayed with HWinfo plugin.
Ok, add the following two options to the measure which returns the string:

Code: Select all

RegExpSubstitute=1
Substitute="^(.*) \(.*\) \(.*\)$":"\1"
User avatar
alexks_101
Posts: 4
Joined: August 2nd, 2018, 10:26 am
Location: Corsica

Re: Need some help with regex

Post by alexks_101 »

Thank you, it works :)

Another one sorry, what should I do to have "ST1000DM010-2EP102" instead of "Drive: ST1000DM010-2EP102 (Z9AG4E2F)"?
I'm able to remove the "Drive:" but can't get rid of the " (Z9AG4E2F)".

Regex is just a nightmare for me, I can't stand it, I remember when I had to tweak some htaccess files :-(
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Need some help with regex

Post by balala »

alexks_101 wrote:Another one sorry, what should I do to have "ST1000DM010-2EP102" instead of "Drive: ST1000DM010-2EP102 (Z9AG4E2F)"?
I'm able to remove the "Drive:" but can't get rid of the " (Z9AG4E2F)".

Code: Select all

RegExpSubstitute=1
Substitute="^Drive: (.*) \(.*\)$":"\1"
What is important is to keep in mind that the parenthesis are reserves characters in regular expressions and as such, you have to escape them, using a backslash (\). That's why I put a such character in both posted substitutions, before the parenthesis which exist in the expression.
alexks_101 wrote:Regex is just a nightmare for me, I can't stand it, I remember when I had to tweak some htaccess files :-(
For all of us, especially at the beginning.
User avatar
alexks_101
Posts: 4
Joined: August 2nd, 2018, 10:26 am
Location: Corsica

Re: Need some help with regex

Post by alexks_101 »

Thanks :)

Yeah I know about escaping characters, but the problem regarding regex is the whole syntax.
And I must be dumb because I'm used to programming languages and other related stuff.

Thank you again, have a nice day!
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Need some help with regex

Post by balala »

alexks_101 wrote:but the problem regarding regex is the whole syntax.
And I must be dumb because I'm used to programming languages and other related stuff.
I'm glad if I helped.
No, you're not dumb at all, but the regular expressions have a logic which have to get used to. Probably a programming language background can help, but you have to invest an effort to get used to it.