Pages: 1
RSS
A little lost with REGEXP, Trying to work out how to reduce a string
 
I have a rather complex string I would like to shorten and forward to an SMS gateway. initially the message came from a LoRa gateway that sends in HTML format and to be honest it is a real mess. Thankfully The Bat takes care of most of that and chops is down to plain text. however there is still information that is not needed.

The string is Alert FSI-Temp 3 (641093042320)Content:The temperature is 42 ℃, which has exceeded the threshold 30 ℃.Date:2019-10-12 14:55:44 UTC+10Temperature:42.8 ℃Humidity:19.5 %Note: The listed data was updated at 2019-10-12 14:55:24 UTC+10  iOS Android Official Website  Ursalink Cloud  Contact Us


All i really need from that is something like this..



Alert FSI-Temp 3 (641093042320) Temperature:42.8 ℃Humidity:19.5 %
Threshold exceeded 30 ℃.
Date:2019-10-12 14:55:44 UTC+10

FSI-Temp 3 is the Name of the sensor and will change
(641093042320) is the ID of the sensor and will change

Would anyone please be able to assist me in creating an expression to filter this information so it can be forwarded to the SMS gateway.

Regards
Andrew
 
Sadly I suck at RegEx, so I cannot help you, but the good news is that Regular Expressions are a universal language and The Bat is only one of thousands of applications that use them. So, if you cannot find the answer here, you could also ask your question in basically any forum dedicated to programming in general or to RegEx in particular.
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
 
I know this question was asked a long time ago, but perhaps someone might be interested

Tested string:
"
Alert FSI-Temp 3 (641093042320)Content:The temperature is 42 ℃, which has exceeded the threshold 30 ℃.Date:2019-10-12 14:55:44 UTC+10Temperature:42.8 ℃Humidity:19.5 %Note: The listed data was updated at 2019-10-12 14:55:24 UTC+10  iOS Android Official Website  Ursalink Cloud  Contact Us
"

Regex:
"
(^.* )(\(\d+\)).*?(emperature) is (\d+).* ℃.*?(exceeded) the t(hreshold )(\d+) (℃)\.(Date.*?UTC\+\d+)(.*℃)([^:]+):([^ %]+).*
"

Replaced with:
"
$1$2 T$3: $4$8 $11: $12%\nT$6$5 $7$8.\n$9
"

I haven't tested this in The Bat!, but it works in https://regexr.com/4lvrs
Good luck.
 
I'll trust that it works.. :)   Brilliant, Ariel, thank you for posting this.

To me, regex (along with code written in C) always looks so abstract that I do not even attempt to decypher it..  :o
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
 
The Bat! serves very well the regular expressions, but it has some limitations and differences comparing to Perl language. First, you have to define and use reply template to reply messages received from LoRa gateway. These replies should be directed to SMS gateway, and you have to configure it in the reply template. I checked combination of macros with regular expressions and here is working example of reply template:

Assumptions:
  1. String being a result of original LoRa message will be inserted in the variable callled here %_LoRa. I do not know how to get this string, but assigning it to the variable is simple in the reply template: %_LoRa="string".
  2. Assume the e-mail address of SMS gateway is SMS@gate.way.
Code
%To=""%-
%To="SMS@gate.way"%-
%_LoRa="string"%-
%SetPattRegexp="(?im)(^.*)(\(\d+\)).*?T(emperature) is (\d+).* \xB0C.*?(exceeded) the t(hreshold )(\d+) (\xB0C)\.(Date.*?UTC\+\d+)(.*\xB0C)(Humidity:\d+\.\d).*"%-
%RegexpBlindMatch="%_LoRa"%-
%SubPatt="1" %SubPatt="2" %SubPatt="10" %SubPatt="11"%
T%SubPatt="6" %SubPatt="5" %SubPatt="7" %SubPatt="8"
%SubPatt="9"
You should insert this code, e.g., in a quick template, remembering to modify it (real address of SMS gateway and source of analysed original string). You should obtain the following result (from your example string):

Code
Alert FSI-Temp 3 (641093042320) Temperature:42.8 °C Humidity:19.5%
Threshold  exceeded 30 °C
Date:2019-10-12 14:55:44 UTC+10
Edited: Zygmunt Wereszczyński - 11 January 2022 01:23:28 (Correction of regexp)
Pages: 1