Regex library with same functions as in PB

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
bbanelli
Posts: 107
Joined: Mon Jul 13, 2015 7:40 am

Regex library with same functions as in PB

Post by bbanelli »

Greetings to all,

quite simple - having functions like ExamineRegularExpression(), NextRegularExpressionMatch(), RegularExpressionGroup(), RegularExpressionMatchString() and others missing in SB?

I am no expert but this implementation of regex in SB makes is quite inferior to one in PB, not to mention code cannot be recycled; at least that should be rather straight forward with regex manipulation.

With my best,

Bruno
"If you lie to the compiler, it will get its revenge."
Henry Spencer
http://www.pci-z.com/
User avatar
Tristano
Posts: 5
Joined: Fri Jun 19, 2020 12:24 am
Location: Italy
Contact:

Re: Regex library with same functions as in PB

Post by Tristano »

bbanelli wrote:not to mention code cannot be recycled; at least that should be rather straight forward with regex manipulation.
Even if SB native commands for RegEx were identical to those available in PB, you might still be unable to recycle code (i.e. make it cross-architecture — PB x86 & web) unless SB is using PCRE. See my question:

viewtopic.php?f=6&t=1943
https://www.regular-expressions.info/javascript.html

If SB is leveraging JavaScript's native RegExs, then the supported notations and features will largely depend on which browser is running the SB app:

viewtopic.php?f=6&t=1943

In Chrome, you'd be able to enjoy the latest features from ECMA 2018, but if you're targeting a Win app that relies on the WebBrowser control (IE7-11), or a CHM Help document (IE7), then you're stuck with a pretty poor RegEx subset.

For a comparison of the differences between JS and PCRE RegEx, see:

https://web.archive.org/web/20130830063 ... avors.html

There are 3rd party alternative libraries, like XRegExp, which are much better but still not 100% PCRE compliant:

http://xregexp.com/

So, unless SB where to adopt the original PCRE library used by PB (i.e. cross compiling it via tools like Emscripten) portability of RegExs definitions between PB and SB is going to be an issue.

I was quite surprised to discover that none of the above considerations are being mentioned in SB Help docs, for they seem rather important aspects of working with RegExs (a developer needs to know exactly which RegEx flavour is working with, so that he/she can consult the correct documentation and be able to predict browser-dependent differences).
Post Reply