It is currently March 29th, 2024, 1:53 am

RegExp Question

Get help with creating, editing & fixing problems with skins
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

RegExp Question

Post by gkmaz9 »

[TXT Note]
01 A
02 B
03 C

There is an txt file like this.
I can get A by RegExp=(?siU)01 (.*)02
(WebParser.dll)
-------
But [txt File] can be Changed as follows.

[TXT Note]
01 A
03 C

or

[TXT Note]
01 A
-------
Even in this situation, I want to get an only A.
What should I write on RegExp?
Last edited by gkmaz9 on August 28th, 2019, 5:47 pm, edited 2 times in total.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp Question

Post by jsmorley »

While I'm suspicious that the pattern you posted is not exactly what you are going to get, so I'm making some assumptions here that may not be valid, I would in any case approach it using "lookahead assertions", so it won't "fail" if there are missing entries.

Test.txt:

Code: Select all

[TXT Note]
01 A
02 B
03 C
Test.ini:

Code: Select all

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

[MeasureAll]
Measure=WebParser
URL=file://#CURRENTPATH#Test.txt
RegExp=(?siU).*\r\n.*(?(?=.* .*\r\n).* (.*)\n)(?(?=.* .*\r\n).* (.*)\r\n)(?(?=.* .*\r\n).* (.*)\r\n)
LogSubstringErrors=0

[MeasureA]
Measure=WebParser
URL=[MeasureAll]
StringIndex=1

[MeasureB]
Measure=WebParser
URL=[MeasureAll]
StringIndex=2

[MeasureC]
Measure=WebParser
URL=[MeasureAll]
StringIndex=3

[MeterA]
Meter=String
MeasureName=MeasureA
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1

[MeterB]
Meter=String
MeasureName=MeasureB
Y=R
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1

[MeterC]
Meter=String
MeasureName=MeasureC
Y=R
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=0,0,0,1
AntiAlias=1


1.jpg


And then...

Test.txt:

Code: Select all

[TXT Note]
01 A
03 C

2.jpg


https://docs.rainmeter.net/tips/webparser-lookahead-assertions-in-regexp/

The key to this is the repeating (?(?=.* .*\r\n).* (.*)\r\n) bits. What this is saying is:

(? start the lookhead.
(?=.* .*\r\n) ask the question, "is there a pattern coming up of any number of any characters, followed by a space, then any number of any characters followed by a carriage return and linefeed?" .
.* (.*)\r\n if so, get that pattern and capture what is after the space and before the carriage return. That's going to be the A/B/C.
) end the lookahead.

Repeat that as many times as there can possibly be matches.

The \r\n pattern assumes the text file is a "Windows" formatted text file, with carriage return / linefeed endings. If the file is created in some unix environment, like from the web, then just use \n alone.
You do not have the required permissions to view the files attached to this post.
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: RegExp Question

Post by gkmaz9 »

Thank you for your answer.

But my explanation was inaccurate.
The actual text file is like this.
(text files will continue to change.)

Text.txt

01 - A0
01 - A1
01 - A2
01 - A3
02 - B1
02 - B2
03 - C0
03 - C1
03 - C2
.
.
.
24-Z1
24-Z6

Sometimes it changes like this.
Text.txt

01 - A0
01 - A1
03 - C0
03 - C2
.
.
14 - j2
24 - O3
.
.
24-Z6

Sometimes it changes like this.
Text.txt

01 - A0




The price I want to get is next.
For example, if the first txt file is,
A
A1
A2
A3

The second txt file,
A0
A1

(I will remove " -" with "Substitute" )

In short, what I want...This is it.
I want to extract all the values marked 01 from the beginning to the end.
Last edited by gkmaz9 on August 28th, 2019, 4:00 pm, edited 2 times in total.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp Question

Post by jsmorley »

Yeah, I don't follow at all. Can you give some "real" examples?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp Question

Post by jsmorley »

You are going to need to know some "maximum" number of entries possible. You have to create a hard-coded WebParser child measure, and a hard-coded String meter for each.
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: RegExp Question

Post by gkmaz9 »

I want to get all the Gr. of 01hour(01:--)
...even if txt file will be change

test.txt

Code: Select all

[Variables]
6= 01: 29 - Gr. 18
7= 01: 39 - Gr. 1
8= 02: 39 - 0
9= 02: 40 - Gr. 0
10= 03: 02 - Gr. 18
11= 03: 04 - Gr. 0
12= 03: 06 - Gr. 0
13= 03: 08 - Gr. 0
14= 04: 02 - Gr. 0
test2.txt

Code: Select all

[Variables]
6= 01: 29 - Gr. 18
11= 03: 04 - Gr. 0
12= 03: 06 - Gr. 0
13= 03: 08 - Gr. 0
14= 04: 02 - Gr. 0
test3.txt

Code: Select all

[Variables]
6= 01: 29 - Gr. 18
11= 01: 44 - Gr. 44

ini file

Code: Select all

[meterdata]

Name=SongSong
Author=J.H.LEE
Version=1.0

[rainmeter]
Update=1000



[Variables]
@include=C:\Users\USER\Documents\Rainmeter\Skins\Tree\@Resources\Log\Test.txt
XX="10= ":"","11= ":"","12= ":"","13= ":"","14= ":"","15= ":"","16= ":"","17= ":"","18= ":"","19= ":"","20= ":"","21= ":"","22= ":"","23= ":"","24= ":"","25= ":"","26= ":"","27= ":"","28= ":"","29= ":"","30= ":"","31= ":"","32= ":"","33= ":"","34= ":"","35= ":"","36= ":"","37= ":"","38= ":"","39= ":"","40= ":"","41= ":"","42= ":"","43= ":"","44= ":"","45= ":"","46= ":"","47= ":"","48= ":"","49= ":"","50= ":"","51= ":"","52= ":"","53= ":"","54= ":"","55= ":"","56= ":"","57= ":"","58= ":"","59= ":"","60= ":"","1= ":"","2= ":"","3= ":"","4= ":"","5= ":"","6= ":"","7= ":"","8= ":"","9= ":""
XXWhite=255,255,255,100
XXSize=10
XXFontColor=255,255,255,255
XXTimeWide=35
XXX=50


 ;Please change "Url=#%^$#" to the appropriate path. 
 ;test.txt file will be Change... test2.txt or test3.txt

[1Hour]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=file://C:\Users\USER\Documents\Rainmeter\Skins\Tree\@Resources\Log\Test.txt
RegExp=(?siU)01: (.*)02: 
StringIndex=1
Substitute="01: ":"","#XX#"


[OutPut1]
meter=String
MeasureName=1Hour
FontSize=#XXSize#
FontColor=#XXFontColor#
SolidColor=#XXWhite#
DynamicVariables = 1 
Text=%1
X=#XXX#
Y=50
W=400

[CheckHour1]
meter=String
FontSize=#XXSize#
FontColor=#XXFontColor#
DynamicVariables = 1 
Text=1H
SolidColor=#XXWhite#
X=([OutPut1:X]-#XXTimeWide#-1) 
Y=0r
W=#XXTimeWide#
H=([OutPut1:H])

User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp Question

Post by jsmorley »

How many instances of 01: can there possibly be?
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: RegExp Question

Post by gkmaz9 »

I have to get [all Lines containing "01:" ] at once. That's all.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: RegExp Question

Post by jsmorley »

gkmaz9 wrote: August 28th, 2019, 4:25 pm I have to get [all Lines containing "01:" ] at once. That's all.
Regular expression doesn't really work that way. There is no such concept as some undefined number that is "all" of anything. You have to get the values for the lines that match on 01: in individual (captures) and create WebParser child measures for each and some way to display the results.
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: RegExp Question

Post by gkmaz9 »

The quantity of 01 changes freely.
It can be 0 or 3 or 100.

So... at first, I set RegExp between 01 and 02.

However, there are times when 03 or 04 comes instead of 02(in regular order).
Also, there are times when there are only 01.