It is currently March 28th, 2024, 8:00 pm

[SOLVED] Need help pls: InlinePattern capturing parts of string

Get help with creating, editing & fixing problems with skins
User avatar
nmdelrio
Posts: 74
Joined: June 28th, 2015, 12:51 pm
Location: Paranaque City, Philippines

[SOLVED] Need help pls: InlinePattern capturing parts of string

Post by nmdelrio »

I have a string meter that shows time (h:m:s), date (date:month:day) as shown:

1127471402TUE

The first 2 pairs of digits are the time (i.e., 1127), the third pair (i.e. 47) are the seconds, the 4th and 5th pair are the date (i.e. 1402, as in 14 Feb), and the last the day (i.e. TUE).

How do I use InlinePattern to capture parts of the string so that the string appears as

1127471402TUE

I started with

Code: Select all

InlineSetting=Color|255,0,0,255
InlinePattern=^\d\d\d\d
InlineSetting2=Color|0,0,255,255
InlinePattern2=
and managed to capture the first 4 digits, but sadly that's as far as I was able to progress.

I understand InlinePattern is compatible to PCRE. I went to that site, but just could not understand how to do it.

Can anyone please help? Can anyone point me to the right direction where the the PCRE expressions are explained?
Last edited by nmdelrio on February 14th, 2017, 5:36 am, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Need help pls: InlinePattern capturing parts of string

Post by jsmorley »

Code: Select all

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

[MeasureString]
Measure=String
String=1127471402TUE

[MeterString]
Meter=String
MeasureName=MeasureString
InlineSetting=Size | 20
InlineSetting2=Color | 235,120,120,255
InlinePattern2=^([\d]{4})[\d]{2}[\d]{4}[\w]{3}$
InlineSetting3=Color | 127,177,227,255
InlinePattern3=^[\d]{4}([\d]{2})[\d]{4}[\w]{3}$
InlineSetting4=Color | 120,235,120,255
InlinePattern4=^[\d]{4}[\d]{2}([\d]{4})[\w]{3}$
InlineSetting5=Color | 235,235,120,255
InlinePattern5=^[\d]{4}[\d]{2}[\d]{4}([\w]{3})$
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
1.jpg
So in each InlinePattern(N) the part of the string that is impacted is the part that is (captured) using parentheses.

In InlinePattern2, we are (capturing) a character class of [\d] which is "a numeric digit", with a repetition count of {4}.
Then we move in InlinePattern3 to (capture) a character class of [\d], again a digit, with a count of {2}.
And so on with InlinePattern4...
In InlinePattern5, we are not looking for numeric digits but a character class of [\w] or "word" characters.

^ means "start of the string" and $ means "end of the string".

https://docs.rainmeter.net/manual/skins/option-types/#RegExp
You do not have the required permissions to view the files attached to this post.
User avatar
nmdelrio
Posts: 74
Joined: June 28th, 2015, 12:51 pm
Location: Paranaque City, Philippines

Re: Need help pls: InlinePattern capturing parts of string

Post by nmdelrio »

A big thank you to you Sir.

The way you did it showed me how to capture parts of a string.

So, alternatively InlinePattern2 can also be written as:

InlinePattern2=^([\d]{4})[\d]{6}[\w]{3}$

Instead of

...[\d]{2}[\d]{4}...

it can also be

...[\d]{6}...

Of course the way you wrote it is the way I grouped the "parts" to be captured and is the better way, and would also be easier to just keep moving the parenthesis to the next group in the subsequent InlinePatterns.

Previously, I used separate meters for each group of digits and "stitched" them with x and y positions, which was fine (though not at all near to being professional) when using monospace fonts, But for non-monospaced fonts, the spacing goes out of whack because of the fixed x and y positions for each meter. Now I can use any font at the same time maintaining the appropriate spacing between each character. Very nice.

Thank you also for the link to tutorials on regular expressions (so that's what RegEx means, duh). :thumbup:
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Need help pls: InlinePattern capturing parts of string

Post by jsmorley »

nmdelrio wrote:A big thank you to you Sir.

The way you did it showed me how to capture parts of a string.

So, alternatively InlinePattern2 can also be written as:

InlinePattern2=^([\d]{4})[\d]{6}[\w]{3}$

Instead of

...[\d]{2}[\d]{4}...

it can also be

...[\d]{6}...

Of course the way you wrote it is the way I grouped the "parts" to be captured and is the better way, and would also be easier to just keep moving the parenthesis to the next group in the subsequent InlinePatterns.

Previously, I used separate meters for each group of digits and "stitched" them with x and y positions, which was fine (though not at all near to being professional) when using monospace fonts, But for non-monospaced fonts, the spacing goes out of whack because of the fixed x and y positions for each meter. Now I can use any font at the same time maintaining the appropriate spacing between each character. Very nice.

Thank you also for the link to tutorials on regular expressions (so that's what RegEx means, duh). :thumbup:
Yeah, the way I did it is not the only way for sure, but I felt like it was the easiest to follow for someone sorta new to it. Just using the same pattern, and moving the parentheses. Anyway, glad to help.
User avatar
nmdelrio
Posts: 74
Joined: June 28th, 2015, 12:51 pm
Location: Paranaque City, Philippines

Re: [SOLVED] Need help pls: InlinePattern capturing parts of string

Post by nmdelrio »

You are correct about that, Sir, it took me no time to understand it. :D