It is currently March 29th, 2024, 3:46 pm

Regex issue/bug ?

Get help with creating, editing & fixing problems with skins
aeris
Posts: 4
Joined: November 9th, 2017, 4:49 pm

Regex issue/bug ?

Post by aeris »

Hi,

I use webparser like this :

Code: Select all

[measureCorsairLink]
Measure			= Plugin
Plugin			= WebParser
UpdateRate		= 10
URL				= file://#corsairLinkFile#
RegExp			= (?iU).*,(\d+),\d°C,(\d+) rpm,(\d+)V, (\d+,\d)A,(\d+,\d)\d*%, (\d+),\d*W, (\d+),\d*W.*$
FinishAction	= !CommandMeasure "MeasureLUA" "Clear()"
The file is a .csv text file like :

Code: Select all


09/11/2017 17:54:37,32,0°C,800 rpm,219V, 2,9A,93,1498867242065%, 635,55W, 592,014105075694W
09/11/2017 17:54:39,32,0°C,808 rpm,219V, 2,9A,93,1498867242065%, 635,55W, 592,014105075694W
09/11/2017 17:54:41,32,0°C,792 rpm,219V, 2,9A,93,142738992544%, 637,55W, 593,831532446965W
09/11/2017 17:54:43,32,0°C,808 rpm,219V, 2,9A,93,142738992544%, 637,55W, 593,831532446965W
(with a CRLF in the first line)

The regex work in RainRegEx :

Code: Select all

1 => 32
2 => 808
3 => 219
4 => 2,9
5 => 93,1
6 => 637
7 => 593
But doesn't in Rainmeter :

Code: Select all

RegExp matching error (-1) (perso\CorsairPSU\CorsairPSU.ini - [measureCorsairLink])
I try with disabling the FinishAction and LUA script, it's not an issue/conflict with the LUA script.

Do you have an idea, please ?

Thanks.


PS : edited
Last edited by aeris on November 9th, 2017, 11:39 pm, edited 3 times in total.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Regex issue/bug ?

Post by balala »

We don't know what that .lua file contains, but I rewrote the RegExp option, here is my new one: RegExp=(?siU)\n(.*),(\d*,?\d*)°C,(\d+) rpm,(\d+)V, (\d*,?\d*)A,(\d*,?\d*)%, (\d*,?\d*)W, (\d*,?\d*)W. Try this one and let me know if this one is working better.
aeris
Posts: 4
Joined: November 9th, 2017, 4:49 pm

Re: Regex issue/bug ?

Post by aeris »

balala wrote:We don't know what that .lua file contains, but I rewrote the RegExp option, here is my new one: RegExp=(?siU)\n(.*),(\d*,?\d*)°C,(\d+) rpm,(\d+)V, (\d*,?\d*)A,(\d*,?\d*)%, (\d*,?\d*)W, (\d*,?\d*)W. Try this one and let me know if this one is working better.
Thanks for your reply, but :
- I don't need 's' flag, it's only for dots ?
- if we put \n at the start it can't parse the last line ?
- + is a good idea, but not solve the issue
- on some variable I really don't want decimal :D
- I put .* at the end for the case of CRLF
arty_fish
Posts: 14
Joined: June 7th, 2016, 7:04 am

Re: Regex issue/bug ?

Post by arty_fish »

Do you have the skin saved as UTF-8?

If so, webparser isn't handling the degree symbol. Either save to ANSI or UCS-2 LE BOM

OR

use . to represent the degree symbol and it will parse as UTF-8.

Rainmeter and unicode is described here:

https://docs.rainmeter.net/tips/unicode-in-rainmeter/
aeris
Posts: 4
Joined: November 9th, 2017, 4:49 pm

Re: Regex issue/bug ?

Post by aeris »

arty_fish wrote:Do you have the skin saved as UTF-8?

If so, webparser isn't handling the degree symbol. Either save to ANSI or UCS-2 LE BOM

OR

use . to represent the degree symbol and it will parse as UTF-8.

Rainmeter and unicode is described here:

https://docs.rainmeter.net/tips/unicode-in-rainmeter/
That's a really good idea, I replace the ° and % with . but not solved the issue :-/
And I try saving the file in ANSI and UTF8.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Regex issue/bug ?

Post by jsmorley »

To be clear on the encoding...

The text file (the .csv) that you are reading with WebParser must be encoded as UTF-8 w/BOM. Nothing else will work. If this is not something you can control, then you need to find out how it is in fact encoded, and use the correct CodePage setting on your parent WebParser measure.

The skin file (the .ini) must be encoded as UTF-16 Little Endian if you are going to use the degree symbol or other characters not in the ASCII character set in it. If not, then ANSI will be ok, but I recommend UTF-16 Little Endian for ALL Rainmeter skin .ini and .inc files. Never encode any skin .ini or .inc file as UTF-8. It won't work.

When I paste the code you posted from your .csv into RainRegExp it works fine, so the regular expression must be ok.

When I create a little test skin:

Test.ini (encoded as UTF-16 Little Endian)

Code: Select all

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

[measureCorsairLink]
Measure=Plugin
Plugin=WebParser
UpdateRate=10
URL=file://#CURRENTPATH#Test.txt
RegExp=(?iU).*,(\d+),\d°C,(\d+) rpm,(\d+)V, (\d+,\d)A,(\d+,\d)\d*%, (\d+),\d*W, (\d+),\d*W.*$

[MeasureChildOne]
Measure=Plugin
Plugin=WebParser
URL=[measureCorsairLink]
StringIndex=1

[MeterChildOne]
Meter=String
MeasureName=MeasureChildOne
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=The first StringIndex is: %1
Test.txt (encoded as UTF-8 w/BOM)

Code: Select all


09/11/2017 17:54:37,32,0°C,800 rpm,219V, 2,9A,93,1498867242065%, 635,55W, 592,014105075694W
09/11/2017 17:54:39,32,0°C,808 rpm,219V, 2,9A,93,1498867242065%, 635,55W, 592,014105075694W
09/11/2017 17:54:41,32,0°C,792 rpm,219V, 2,9A,93,142738992544%, 637,55W, 593,831532446965W
09/11/2017 17:54:43,32,0°C,808 rpm,219V, 2,9A,93,142738992544%, 637,55W, 593,831532446965W
It works fine for me...
1.png
I do suspect some kind of encoding issue somewhere. It's not about the degree ° symbol, that's fine, don't replace it. It's about how either the skin .ini or text .csv files are encoded.

Some more details you didn't ask for on how encoding works...
There are basically three kinds of encoding you will run into:

ANSI - This is really a throwback to an earlier time before Unicode was invented. What it is is the ASCII characters from decimal 0-127, which are standard English characters, numbers and punctuation, combined with the Extended ASCII characters from 128-255, which are some foreign (mostly Western European) characters like acents and graves and umlauts and the like, as well as some box drawing characters and mathematical symbols.

ANSI is treated as ANSI, this old-school vanilla encoding, by programs as long as it only contains characters from the ASCII character set from 0-127. If you put anything above that, from the Extended ASCII character set, then it will be seen as UTF-8 w/o BOM. Oh, and by the way, what characters are represented by the Extended ASCII character set are dependent on what the codepage / locale is on your Windows system. ANSI is bad for sharing now that the entire world is networked. Don't use it.

Rainmeter hates UTF-8 in any .ini or .inc file.

UTF-8 w/BOM - This is a more modern encoding and includes pretty much the entire Unicode character set. There are some limitations as the world of Unicode is huge and getting huger all the time, but pretty much the entire world-wide-web is encoded using it. It gives you most of the power of UTF-16 or UTF-32 encoding, while requiring sending fewer "bytes" over the internet, always a consideration for online stuff.

Again, Rainmeter hates UTF-8 in any .ini or .inc file.

However, by default that is exactly what WebParser is looking for. Since that is what is pretty much always used on the internet, that makes sense. WebParser wants UTF-8 w/BOM, and you will have to force it to accept anything else, by using the CodePage option.

UTF-16 LIttle Endian - This is the most robust form of Unicode in common use, and in fact since Windows 95 is what Windows itself defaults to for all its programs. Since Windows expects UTF-16 Little Endian in programs by default, that is what Rainmeter uses.

Rainmeter really likes UTF-16 Little Endian in .ini and .inc files. Just always use it.

You can in fact use ANSI for skin files, since in a sense ANSI is "no encoding", but be careful. As soon as you put anything other than ASCII in the file, it will be seen as UTF-8, and Rainmeter will hate it.

Hope this helps some.
You do not have the required permissions to view the files attached to this post.
aeris
Posts: 4
Joined: November 9th, 2017, 4:49 pm

Re: Regex issue/bug ?

Post by aeris »

jsmorley wrote:...
Ho yes, that's work !

Big thanks and big kiss !
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Regex issue/bug ?

Post by jsmorley »

aeris wrote:Ho yes, that's work !

Big thanks and big kiss !
Glad to help.