It is currently March 28th, 2024, 2:45 pm

In RegExp to remove tabs and spaces and line breaks before and after the phrase

Get help with creating, editing & fixing problems with skins
User avatar
ZerOverdriver
Posts: 29
Joined: February 13th, 2017, 8:57 pm

In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by ZerOverdriver »

Hi, friends!
Help please , I have enough knowledge to solve this problem.

RegExp="(?siU)the first piece of code(.*)the second piece of code.*"

In the first case it is necessary not to read the tabs and spaces and line breaks until the start of the phrase.
here the phrase appears as follows:

TabTabSpaceSpaceSpaceLineWrapping
TabTabSpaceSpaceSpaceWord Word


In the second case it is not necessary to show the spaces and tabs and line break after the phrase.
here the phrase appears as follows:

Word WordTabTabSpaceSpaceSpaceLineWrapping
TabTabSpaceSpaceSpace


What is the syntax of RegExp to use for such cases?
Or maybe you can help in this case Substitute?
But you need to space between the words remained.
Last edited by ZerOverdriver on December 7th, 2017, 9:21 pm, edited 7 times in total.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by FreeRaider »

I do not understand what you want.
Please give a "real" example.
User avatar
ZerOverdriver
Posts: 29
Joined: February 13th, 2017, 8:57 pm

Re: In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by ZerOverdriver »

FreeRaider wrote:I do not understand what you want.
Please give a "real" example.
I corrected my first message and now attached image:

The top screenshot is the second problem.
The lower screenshot is the first problem.
I uploaded the images incorrectly.
Blue highlighted words, which are necessary, and the void around them - you need to clean.
Attachments
2017-12-06_23-08-51.png
2017-12-06_23-02-25.png
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by FreeRaider »

Next time please post a piece of code or a piece of the page you want to capture between "code" tags.

The only thing I can tell you is a list of tokens concerning your problem:

\t Tab
\r Carriage return character
\n Line feed character
\r\n Line separator on Windows
\N Perl, PCRE (C, PHP, R…): one character that is not a line break
\h Perl, PCRE (C, PHP, R…), Java: one horizontal whitespace character: tab or Unicode space separator
\H One character that is not a horizontal whitespace
\v .NET, JavaScript, Python, Ruby: vertical tab
\v Perl, PCRE (C, PHP, R…), Java: one vertical whitespace character: line feed, carriage return, vertical tab, form feed, paragraph or line separator
\V Perl, PCRE (C, PHP, R…), Java: any character that is not a vertical whitespace
\R Perl, PCRE (C, PHP, R…), Java: one line break (carriage return + line feed pair, and all the characters matched by \v)
\s Most engines: "whitespace character": space, tab, newline, carriage return, vertical tab
\s .NET, Python 3, JavaScript: "whitespace character": any Unicode separator
\S One character that is not a whitespace character as defined by your engine's \s

Good luck.
User avatar
ZerOverdriver
Posts: 29
Joined: February 13th, 2017, 8:57 pm

Re: In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by ZerOverdriver »

I'm sorry!
Here is the piece of code as You requested.
Of course it's more convenient and more understandable.
Please help to solve this problem!

Code: Select all

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

[Variables]
URL=http://www.foreca.com/Russia/Moscow?quick_units=metric&tf=24h&lang=us
URL2=http://www.foreca.com/Russia/Moscow?tenday

[MeasureConditions]
Measure=Plugin
Plugin=WebParser
Url=#URL#
RegExp="(?siU)<div class="right txt-tight">(.*)<br />.*"
UpdateRate=1800
StringIndex=1

[MeasureVtr]
Measure=Plugin
Plugin=WebParser
UpdateRate=1800
Url=#URL2#
RegExp="(?siU).*<span class="h5">Today</span>.*<img src="//img-b.foreca.net/s/symb-wind/(.*).gif".*<strong>(.*)</strong>(.*)</span></span>.*"
StringIndex=3

;------------------------------------------

[MeterConditions]
Meter=String
MeasureName=MeasureConditions
X=0
Y=0
FontFace=Arial
FontSize=14
FontColor=255,255,255,255
SolidColor=47,47,47,200
Padding=5,5,5,5
AntiAlias=1
Text="Conditions:%1(end string)"

[MeterVtr]
Meter=String
MeasureName=MeasureVtr
X=к
Y=5R
FontFace=Arial
FontSize=14
FontColor=255,255,255,255
SolidColor=47,47,47,200
Padding=5,5,5,5
AntiAlias=1
Text="Speed:%1(end string)"

Last edited by ZerOverdriver on December 8th, 2017, 8:43 am, edited 1 time in total.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by FreeRaider »

Try this code

Code: Select all

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

[Variables]
URL=http://www.foreca.com/Russia/Moscow?quick_units=metric&tf=24h&lang=us
URL2=http://www.foreca.com/Russia/Moscow?tenday

[MeasureConditions]
Measure=Plugin
Plugin=WebParser
Url=#URL#
RegExp="(?siU).*<div class="right txt-tight">\W{1,}+(.*)<br />.*"
UpdateRate=1800
StringIndex=1

[MeasureVtr]
Measure=Plugin
Plugin=WebParser
UpdateRate=1800
Url=#URL2#
RegExp="(?siU).*<span class="h5">Today</span>.*<img src="//img-b.foreca.net/s/symb-wind/(.*).gif".*<strong>(.*)</strong>\s+(.*)\s+</span></span>.*"
StringIndex=3

;------------------------------------------

[MeterConditions]
Meter=String
MeasureName=MeasureConditions
FontFace=Arial
FontSize=14
FontColor=255,255,255,255
SolidColor=47,47,47,200
Padding=5,5,5,5
AntiAlias=1
Text="Conditions:%1Endstring"

[MeterVtr]
Meter=String
Y=0R
MeasureName=MeasureVtr
FontFace=Arial
FontSize=14
FontColor=255,255,255,255
SolidColor=47,47,47,200
Padding=5,5,5,5
AntiAlias=1
Text="Speed:%1(end string)"
The first RegExp option:
RegExp="(?siU).*<div class="right txt-tight">\W{1,}+(.*)<br />.*"

The second RegExp option:
RegExp="(?siU).*<span class="h5">Today</span>.*<img src="//img-b.foreca.net/s/symb-wind/(.*).gif".*<strong>(.*)</strong>\s+(.*)\s+</span></span>.*"

I hope this helps you
User avatar
ZerOverdriver
Posts: 29
Joined: February 13th, 2017, 8:57 pm

Re: In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by ZerOverdriver »

Thank You very much! :thumbup:
For your help and patience. :bow:
This method works very good, this is what I need. :great:

Now I've been experimenting with different versions of indents before and after values, and seems to have found a universal method for such cases:
RegExp="(?siU)...\W{1,}+(.*)\s{0,}+....*
This code is correct?
Of course this only works if there is at least one space before the text.

I think that it would be nice if the plugin WebParser empties edges of the text cut off automatically for easy alignment of text in Rainmeter? :D
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by FreeRaider »

Glad to help.
At this point, have you tried \W{0,}+(.*)\s{0,}+?
User avatar
ZerOverdriver
Posts: 29
Joined: February 13th, 2017, 8:57 pm

Re: In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by ZerOverdriver »

FreeRaider wrote:Glad to help.
At this point, have you tried \W{0,}+(.*)\s{0,}+?
Yes, it works everywhere, even if the text has no voids on the edges, so this method could be considered and used in the plugin.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: In RegExp to remove tabs and spaces and line breaks before and after the phrase

Post by jsmorley »

ZerOverdriver wrote:Yes, it works everywhere, even if the text has no voids on the edges, so this method could be considered and used in the plugin.
WebParser can't make any assumptions like that. You might want the leading spaces. You just have to write the RegExp correctly, or use Substitute to strip off spaces.
Post Reply