Any chance for RegExp support?

Give it a try, it costs you nothing !
Post Reply
SteanX
Posts: 39
Joined: Sat Jun 19, 2021 10:33 pm
Has thanked: 17 times
Been thanked: 6 times

Any chance for RegExp support?

Post by SteanX »

I was wondering if you might consider bringing Regular Expression support to Annex?
While Instr, Left$,Right$ and Mid$ can sortof do the job, I really miss RegExp to extract snippets coming from some serial device :-(
There is a pretty old Arduino RegExp library that might be of use at https://github.com/nickgammon/Regexp. I am not sure what style of RegExp this library supports, the documentation says he ported it from LUA.

As always cicciocb, just if you think it adds value and is something of interest. I can imagine that the possibility that a RegExp can return matches that might be an array of varying size exposed in Annex, could be challenging. Plus, it would make the case to implement that UBound() function that someone asked for a while ago to be able to process such a matches array :-)
User avatar
cicciocb
Site Admin
Posts: 2057
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: Any chance for RegExp support?

Post by cicciocb »

Yes, it could be a nice feature.
User avatar
cicciocb
Site Admin
Posts: 2057
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: Any chance for RegExp support?

Post by cicciocb »

SteanX,
I've integrated the regex library into Annex with a temporary syntax implementation.

Do you have an ESP32-S3 for testing or you own only classic ESP32?
SteanX
Posts: 39
Joined: Sat Jun 19, 2021 10:33 pm
Has thanked: 17 times
Been thanked: 6 times

Re: Any chance for RegExp support?

Post by SteanX »

That's awesome, thanks! I have both classic and S3 available.
User avatar
cicciocb
Site Admin
Posts: 2057
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: Any chance for RegExp support?

Post by cicciocb »

OK, I'm drafting a preliminary documentation and I'll post an updated version for the ESP32-S3
User avatar
cicciocb
Site Admin
Posts: 2057
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: Any chance for RegExp support?

Post by cicciocb »

I've just released a new version 1.52.5 for the ESP32-S3.

This version includes :
- Fix for the array variables shown in the editor page when OPTION.BASE 1
- First try for the regex functions (experimental)
- Implemented the functions LBOUND and UBOUND

The preliminary documentation for the regex can be found below:
SteanX
Posts: 39
Joined: Sat Jun 19, 2021 10:33 pm
Has thanked: 17 times
Been thanked: 6 times

Re: Any chance for RegExp support?

Post by SteanX »

Thanks so much for including this CiccioCB. I'll try it out first thing tomorrow morning!
Actually, I couldn't wait, so I just tested it.

Works just fine - I specifically checked the most complex situation which was multiple captures as you described on the last page of the documentation. Also tested it with defining the capture array first DIM A$(Guess) and without - both worked fine. I would imagine the regex.matches function redims the array based on the number of matches?

Thanks also for adding the LBOUND and UBOUND functions - this is really helpful! Awesome. Now I just need to get used to the LUA flavour of regexes - I am more familiar with writing patterns for Javascript and Perl, but I'm sure it will be no problem - WLOG is your friend :-)

Quick question : I will unfortunately need an Annex version that has regex and BLE sometime in the future. I realise that building Annex images can take a serious amount of time, so please, not at all a priority - just one day in the future if you have the time would be appreciated?

I was actually wondering how you decide what support to build into what image? And if sometime, you might consider having a sort of "image builder" that would allow you to compile an image with selectable features (I mean those options on the INFOS button of the flasher's image pages). I unfortunately do not know enough about the build process with the Espressif SDK to know whether it is feasible to script any form of batch compilation of various combinations, but if there's anything I can do to help, even if it is just to provide some VM/container resources to do so, please let me know?

As always, thank you for the effort CiccioCB. And that on a weekend!
User avatar
cicciocb
Site Admin
Posts: 2057
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: Any chance for RegExp support?

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Apr 06, 2024 8:30 pm Works just fine - I specifically checked the most complex situation which was multiple captures as you described on the last page of the documentation. Also tested it with defining the capture array first DIM A$(Guess) and without - both worked fine. I would imagine the regex.matches function redims the array based on the number of matches?
Yes, the capture array is automatically created and redimensioned based on the number of captures.
If already existing, it is simply replaced with the new content.
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Apr 06, 2024 8:30 pm Thanks also for adding the LBOUND and UBOUND functions - this is really helpful! Awesome. Now I just need to get used to the LUA flavour of regexes - I am more familiar with writing patterns for Javascript and Perl, but I'm sure it will be no problem - WLOG is your friend :-)
I tried to implement the "standard" c++ regex but I discovered that these functions are buggy on the ESP32 so I gave up and integrated directly ths library that you suggested as it seems very adapted for this kind of application (very versatile with a low memory footprint). Yes, the pattern syntax is different but very similar so is not hard to convert.
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Apr 06, 2024 8:30 pm Quick question : I will unfortunately need an Annex version that has regex and BLE sometime in the future. I realise that building Annex images can take a serious amount of time, so please, not at all a priority - just one day in the future if you have the time would be appreciated?
The BLE is not in the recent releases because it takes a lot of RAM memory and, according to my understanding, nobody uses it (but apparently I was mistaken).
Yes, compile takes some time and oblige me to do some testing but yes, I plan to release the versions including the BLE.
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Apr 06, 2024 8:30 pm I was actually wondering how you decide what support to build into what image?
The decision of the features to include is mainly oriented based on the interest that I feel on the forum (even if the feedback is practically around zero :lol: ) but essentially driven by the resources that the "feature" consumes (in particular the RAM).
The way I integrate the features aims to minimize the RAM usage when the specific feature is not used but, unfortunately, this is not always achievable.
This is important because the available free RAM in the chip (internal, not external PSRAM) is the main contributor to the stability of Annex.
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Apr 06, 2024 8:30 pm And if sometime, you might consider having a sort of "image builder" that would allow you to compile an image with selectable features (I mean those options on the INFOS button of the flasher's image pages). I unfortunately do not know enough about the build process with the Espressif SDK to know whether it is feasible to script any form of batch compilation of various combinations, but if there's anything I can do to help, even if it is just to provide some VM/container resources to do so, please let me know?
An online "image builder" will require a big effort and the use of a costly web service like gitpod so is not an option.
Probably a better solution could be a donation driven releases? :roll:
Post Reply