It is currently April 26th, 2024, 5:43 pm

Help with RegEx please :)

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7172
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Help with RegEx please :)

Post by Yincognito »

Let me know if this will do (you'd have to create a similar [...AutoScaled] measure for every [m...Free] measure, of course) - this does what NumOfDecimals=2 + AutoScale=1 do, just in the STRING value of the autoscaling MEASURE, instead of in the NUMBER value of the autoscaled METER. I also slightly modified your inline pattern to match only a time value (I suppose that is what was for, right?) so it won't trigger for the drive data:

Code: Select all

[Variables]
Decimals=2

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Measures---

[m1Free]
Measure=FreeDiskSpace
Drive=M:

[m1FreeAutoScaled]
Measure=Calc
Formula=Sgn(m1Free=0?1:m1Free)*(Round(Abs(m1Free)/1024**Trunc(Log(Abs(m1Free)<1?1:Abs(m1Free))/Log(1024)),#Decimals#)+(Trunc(Log(Abs(m1Free)<1?1:Abs(m1Free))/Log(1024))+1)*(10**(-#Decimals#-2)))
RegExpSubstitute=1
Substitute="^(.*\..{#Decimals#}).{1}(.{1}).*$":"\1\2","1$":"[\x200B] ","2$":"[\x200B] k","3$":"[\x200B] M","4$":"[\x200B] G","5$":"[\x200B] T","6$":"[\x200B] P","7$":"[\x200B] E","8$":"[\x200B] Z","9$":"[\x200B] Y","[\x200B]":"","^(.*)$":"\1B","^0\.00 B$":"No Drive"

[meterDrive]
Meter=String
StringEffect=Shadow
FontEffectColor=0,0,0,50
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
InlineSetting=Size | 8
InlinePattern=(?U)^\d+:\d+ (\d+)$
Text=Drive: [m1FreeAutoScaled]
DynamicVariables=1
It's up to you if you want to use this, of course. ;-)
Yet again, long long formulas seem to solve all kinds of issues. :D
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Help with RegEx please :)

Post by sl23 »

That's insane! :rofl: Htf did you come up with that? :o
Sorry, still not working!

It's ok, I think I'll just stick with the 0B that I managed to get it to.

Thanks for the effort though, it was a thing of beauty to witness such a long formula! ;-) :bow:
- MuLab -
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Help with RegEx please :)

Post by sl23 »

I tried going back to where I started just to get the plain '0' when no drive connected, and... I only got it working :p :lol:
"^(.+)$":"\1B","0.00 B":"No Drive"
Well, actually, SilverAzide did! :oops:
Thank you all :D
- MuLab -
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Help with RegEx please :)

Post by sl23 »

Oh damn! Now the InlinePattern doesn't work properly :?
Using InlinePattern=(?U)^\d+:\d+ (\d+)$ basically doesn't format anything.
Using ^.+ (.+)$ shows the Size correctly but when No Drive appears, No is in a larger font than Drive due to the space! O.O
- MuLab -
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Help with RegEx please :)

Post by sl23 »

Solved! With this: Substitute="^(.+)$":"\1B","0.00 B":"" :lol:
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7172
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Help with RegEx please :)

Post by Yincognito »

sl23 wrote: August 7th, 2021, 8:29 pmSorry, still not working!
Sorry, but I'm not the one responsible for the other parts of the code that you didn't show up - my sample posted here works without issues. :confused:
sl23 wrote: August 7th, 2021, 9:44 pmSolved! With this: Substitute="^(.+)$":"\1B","0.00 B":"" :lol:
I doubt that is the case, since:
- if it's not a RegExpSubstitution, it will yield garbage for the part before the comma
- if it is a RegExpSubstitution, the part after the comma will replace a 0, followed by any character (this is what plain dot means in regex), followed by 00 B, with nothing - it won't replace the literal 0.00 B with nothing like you think

--------------
That being said, if you're happy that it works, who am I to disagree? :D
That formula is credit to someone smarter than me on these forums who posted a shorter / more basic version of it for specific cases, a long time ago. I only made it work for anything thrown at it. I use it in my skins too, so I know for sure it works in any scenario. 8-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Help with RegEx please :)

Post by sl23 »

That's ok, I couldn't get it working, so it's obviously something I'm doing wrong. I just decided to make it simple and show nothing. :thumbup:
Yincognito wrote: August 7th, 2021, 10:09 pm I doubt that is the case, since:
- if it's not a RegExpSubstitution, it will yield garbage for the part before the comma
- if it is a RegExpSubstitution, the part after the comma will replace a 0, followed by any character (this is what plain dot means in regex), followed by 00 B, with nothing - it won't replace the literal 0.00 B with nothing like you think
Well, ok, I trust in your knowledge, but that is the effect I get. :confused:
Image 003.png
EDIT: Removal of any part of the Substitution breaks the replacement.
You do not have the required permissions to view the files attached to this post.
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7172
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Help with RegEx please :)

Post by Yincognito »

sl23 wrote: August 7th, 2021, 10:16 pmWell, ok, I trust in your knowledge, but that is the effect I get. :confused:
Image 003.png
Yeah, ok, of course it will show the autoscaled number correctly, but you still didn't get the desired "No Drive" to show up with your "working" Substitute, right? It's the latter part I was referring to when I said what I said.

I don't think the ,"0.00 B":"" part does something in your case...

By the way, can you post the full code?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Help with RegEx please :)

Post by sl23 »

I'll have to take your word for it lol
Thing is, even that last bit is doing something, cos if I change it, it doesn't hide the zero value and the 'B'.

Sure... Here ya go :D

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1

[Metadata]
Name=Drive Info
Author=sl23
Information=Drive Info: Displays 2 disks at a time, but can be changed via L/M/R Mouse click to change between 6 disks.||Credits: Adapted from "SimplyRound" Suite by Krzysztof "gronostaj" Smialek||Help via forum: balala, eclectic-tech, jsmorley
Version=2021.8.7
License=CC BY 3.0

[Variables]
Color1=255,255,255,200
Color2=128,255,0
Color3=128,255,0,200
Color4=0,255,255
Color5=255,255,255,60
Color6=104,191,64,200
Color7=64,143,191,200

; These you can change to your own disks
UserDisk1=C
UserDisk2=D
UserDisk3=E
UserDisk4=F
UserDisk5=G
UserDisk6=H
; DO NOT TOUCH
Disk1=C
Disk2=D

DiskNorm=175,175,175
DiskRead=128,255,0
DiskWrite=255,90,90
DiskBoth=235,170,0

APP1=["explorer.exe" "#Disk1#:\"]
APP2=["#@#\Drives\USBDiskEjector\USB_Disk_Eject.exe """/SHOWEJECT /REMOVELETTER #Disk1#""""]
APP3=["explorer.exe" "#Disk2#:\"]
APP4=["#@#\Drives\USBDiskEjector\USB_Disk_Eject.exe """/SHOWEJECT /REMOVELETTER #Disk2#""""]

NAME1=Open
NAME2=Eject
NAME3=Open
NAME4=Eject

========================================
; Background
========================================
[Bg]
Meter=Shape
Shape=Rectangle 0,0,230,70,35 | Fill Color 0,0,0,150 | StrokeWidth 2 | Extend StrokeAlpha
StrokeAlpha=Stroke Color #Color5#
DynamicVariables=1
X=2
Y=2

[Bg1]
Meter=Shape
Shape=Rectangle 0,0,60,60,50 | Fill Color 0,0,0,50 | StrokeWidth 2 | Extend StrokeAlpha
Shape2=Rectangle 9,9,42,42,50 | Fill Color 0,0,0,1 | StrokeWidth 2 | Extend StrokeAlpha2
Shape3=Rectangle 5,5,50,50,50 | Fill Color 0,0,0,1 | StrokeWidth 10 | Stroke Color 255,255,255,20
StrokeAlpha=Stroke Color #Color5#
StrokeAlpha2=Stroke Color #Color5#

LeftMouseUpAction=#APP1#
RightMouseUpAction=#APP2#

MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color #Color4#"] [!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color #Color5#"] [!UpdateMeter *][!Redraw]

DynamicVariables=1
ToolTipTitle=#Disk1#:/ [m1Label]
ToolTipText=L - #NAME1##CRLF#R - #NAME2##CRLF#
X=7
Y=7

[BgLine]
Meter=Shape
Shape=Rectangle 67,42,100,1,0 | Fill Color #Color5# | StrokeWidth 0
DynamicVariables=1

[Bg2]
Meter=Shape
Shape=Rectangle 0,0,60,60,50 | Fill Color 0,0,0,50 | StrokeWidth 2 | Extend StrokeAlpha
Shape2=Rectangle 9,9,42,42,50 | Fill Color 0,0,0,1 | StrokeWidth 2 | Extend StrokeAlpha2
Shape3=Rectangle 5,5,50,50,50 | Fill Color 0,0,0,1 | StrokeWidth 10 | Stroke Color 255,255,255,20
StrokeAlpha=Stroke Color #Color5#
StrokeAlpha2=Stroke Color #Color5#

LeftMouseUpAction=#APP3#
RightMouseUpAction=#APP4#

MouseOverAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color #Color4#"] [!UpdateMeter *][!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# StrokeAlpha "Stroke Color #Color5#"] [!UpdateMeter *][!Redraw]

DynamicVariables=1
ToolTipTitle=#Disk2#:/ [m2Label]
ToolTipText=L - #NAME3##CRLF#R - #NAME4#
X=167
Y=7

========================================
; STYLES
========================================
[sAllText]
FontFace=Trebuchet MS
StringStyle=Bold
StringAlign=Center
FontSize=12
FontColor=#Color1#
StringEffect=Shadow
FontEffectColor=0,0,0,150
AntiAlias=1
Group=Disk

[sRoundBar]
LineStart=22
LineLength=28
LineWidth=2
StartAngle=(Rad(270))
Antialias=1
Solid=1
Group=Disk

[sHighlight]
MouseOverAction=[!SetOption #CURRENTSECTION# FontColor "128,255,0"] [!UpdateMeter #CURRENTSECTION#] [!Redraw]
MouseLeaveAction=[!SetOption #CURRENTSECTION# FontColor ""] [!UpdateMeter #CURRENTSECTION#] [!Redraw]

[Title]
Meter=String
MeterStyle=sAllText | sHighlight
FontSize=8
Text=DRIVE
LeftMouseUpAction=[!WriteKeyValue Variables Disk1 #UserDisk1#] [!WriteKeyValue Variables Disk2 #UserDisk2#] [!Refresh] 
MiddleMouseUpAction=[!WriteKeyValue Variables Disk1 #UserDisk3#] [!WriteKeyValue Variables Disk2 #UserDisk4#] [!Refresh]
RightMouseUpAction=[!WriteKeyValue Variables Disk1 #UserDisk5#] [!WriteKeyValue Variables Disk2 #UserDisk6#] [!Refresh]
ToolTipText="L - Disk 1+2#CRLF#M - Disk 3+4#CRLF#R - Disk 5+6"
Group=Disk
X=116
Y=29

========================================
; DISK - 1
========================================
[m1Label]
Measure=FreeDiskSpace
Drive=#Disk1#:
UpdateDivider=-1
Label=1

[m1Free]
Measure=FreeDiskSpace
Drive=#Disk1#:
IgnoreRemovable=0
RegExpSubstitute=1
Substitute="^(.+)$":"\1B","0.00 B":""

[m1Total]
Measure=FreeDiskSpace
Drive=#Disk1#:
Total=1
UpdateDivider=-1
IgnoreRemovable=0
Substitute=".00":""
DynamicVariables=1

[mDiskRead1]
Measure=Plugin
Plugin=UsageMonitor
Category=LogicalDisk
Counter=Disk Read Bytes/sec
Name=#Disk1#:

[mDiskWrite1]
Measure=Plugin
Plugin=UsageMonitor
Category=LogicalDisk
Counter=Disk Write Bytes/sec 
Name=#Disk1#:
IfCondition=((mDiskRead1=0)&&(mDiskWrite1=0))
IfTrueAction=[!SetOption 1Label FontColor "#DiskNorm#"] [!UpdateMeter "1Label"] [!Redraw]
IfCondition2=((mDiskRead1>0)&&(mDiskWrite1=0))
IfTrueAction2=[!SetOption 1Label FontColor "#DiskRead#"] [!UpdateMeter "1Label"] [!Redraw]
IfCondition3=((mDiskRead1=0)&&(mDiskWrite1>0))
IfTrueAction3=[!SetOption 1Label FontColor "#DiskWrite#"] [!UpdateMeter "1Label"] [!Redraw]
IfCondition4=((mDiskRead1>0)&&(mDiskWrite1>0))
IfTrueAction4=[!SetOption 1Label FontColor "#DiskBoth#"] [!UpdateMeter "1Label"] [!Redraw]

[m1Used]
Measure=FreeDiskSpace
Drive=#Disk1#:
IgnoreRemovable=0
InvertMeasure=1

[1RoundBar]
Meter=RoundLine
MeterStyle=sRoundBar
MeasureName=m1Used
LineColor=#Color6#
X=37
Y=37

[1Label]
Meter=String
MeterStyle=sAllText
MeasureName=m1Used
Percentual=1
FontSize=16
Text=#Disk1#
X=37
Y=24

[1Free]
Meter=String
MeterStyle=sAllText | sHighlight
MeasureName=m1Free
MeasureName2=m1Total
StringAlign=Left
NumOfDecimals=2
AutoScale=1
Text=%1
ToolTipText="Size: %2B"
InlineSetting=Size | 8
InlinePattern=^.+ (.+)$
X=65
Y=7

========================================
; DISK - 2
========================================
[m2Label]
Measure=FreeDiskSpace
Drive=#Disk2#:
UpdateDivider=-1
Label=1

[m2Free]
Measure=FreeDiskSpace
Drive=#Disk2#:
IgnoreRemovable=0
RegExpSubstitute=1
Substitute="^(.+)$":"\1B","0.00 B":""

[m2Total]
Measure=FreeDiskSpace
Drive=#Disk2#:
Total=1
UpdateDivider=-1
IgnoreRemovable=0
Substitute=".00":""
DynamicVariables=1

[mDiskRead2]
Measure=Plugin
Plugin=UsageMonitor
Category=LogicalDisk
Counter=Disk Read Bytes/sec
Name=#Disk2#:

[mDiskWrite2]
Measure=Plugin
Plugin=UsageMonitor
Category=LogicalDisk
Counter=Disk Write Bytes/sec 
Name=#Disk2#:
IfCondition=((mDiskRead2=0)&&(mDiskWrite2=0))
IfTrueAction=[!SetOption 2Label FontColor "#DiskNorm#"] [!UpdateMeter "2Label"] [!Redraw]
IfCondition2=((mDiskRead2>0)&&(mDiskWrite2=0))
IfTrueAction2=[!SetOption 2Label FontColor "#DiskRead#"] [!UpdateMeter "2Label"] [!Redraw]
IfCondition3=((mDiskRead2=0)&&(mDiskWrite2>0))
IfTrueAction3=[!SetOption 2Label FontColor "#DiskWrite#"] [!UpdateMeter "2Label"] [!Redraw]
IfCondition4=((mDiskRead2>0)&&(mDiskWrite2>0))
IfTrueAction4=[!SetOption 2Label FontColor "#DiskBoth#"] [!UpdateMeter "2Label"] [!Redraw]

[m2Used]
Measure=FreeDiskSpace
Drive=#Disk2#:
IgnoreRemovable=0
InvertMeasure=1

[2RoundBar]
Meter=RoundLine
MeterStyle=sRoundBar
MeasureName=m2Used
LineColor=#Color7#
X=197
Y=37

[2Label]
Meter=String
MeterStyle=sAllText
MeasureName=m2Used
Text=#Disk2#
Percentual=1
FontSize=16
X=197
Y=24

[2Free]
Meter=String
MeterStyle=sAllText | sHighlight
MeasureName=m2Free
MeasureName2=m2Total
StringAlign=Right
NumOfDecimals=2
AutoScale=1
Text=%1
ToolTipText="Size: %2B"
InlineSetting=Size | 8
InlinePattern=^.+ (.+)$
X=166
Y=47
- MuLab -
User avatar
Yincognito
Rainmeter Sage
Posts: 7172
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Help with RegEx please :)

Post by Yincognito »

sl23 wrote: August 7th, 2021, 10:36 pmI'll have to take your word for it lol
Thing is, even that last bit is doing something, cos if I change it, it doesn't hide the zero value and the 'B'.
Actually, I was wrong. I was living under the impression that the autoscaling and the decimal thing is done in the meter itself, but it's done in the measure, which produces a very disturbing effect that the measure's string value is NOT what the user sees in the log, but the value displayed in the measure (e.g. the measure will display 0B as its string value in the Log, while its actual string value would be 0.00 B because of the scaling and digitizing done ... in the meter!). Not sure if I should post it as a bug in the appropriate section, but that's why it works.

That being said try this - if it works, it's the correct way to do it (see the escaped dot \.) and should also correctly display the desired No Drive when stuff is 0 (see the changed pattern):

Code: Select all

[Variables]
Decimals=2

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Measures---

[m1Free]
Measure=Calc
Formula=0
RegExpSubstitute=1
Substitute="^(.+)$":"\1B","^0\.00 B$":"No Drive"

---Meters---

[meterDrive]
Meter=String
StringEffect=Shadow
FontEffectColor=0,0,0,50
SolidColor=47,47,47,255
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
AntiAlias=1
NumOfDecimals=2
AutoScale=1
MeasureName=m1Free
Text=Drive: %1
InlineSetting=Size | 8
InlinePattern=^.+ (.+)(?<!No Drive|[\d\.]+ \wB)$
DynamicVariables=1
I realized the above and tested it without trying your code, so m1Free is just a dummy Calc measure here. Thanks for posting it though.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth