Page 1 of 1

regex

Posted: Tue Oct 28, 2025 10:13 am
by amenjet
Having looked for quite a while and not found an answer, I have this question:

Is regex supported in C on the SDK? (regcomp etc..).

The regex.h file seems to compile fine, is there a library I need to add to get it to work?

Re: regex

Posted: Tue Oct 28, 2025 11:35 am
by katak255
Answered by Google Search AI, also here:

https://answers.launchpad.net/gcc-arm-e ... ion/208555

So it appears to be a POSIX thing, not part of C. If you _really_ need regexes, maybe a standalone implementation would be a good solution, since it is unlikely to ever appear in the arm-none-eabi toolchain.

Re: regex

Posted: Tue Oct 28, 2025 3:32 pm
by amenjet
Yes, this is the POSIX version of the regex stuff. What is odd is that the regex.h file seems to be in the SDK.

Re: regex

Posted: Tue Oct 28, 2025 5:53 pm
by hippy
amenjet wrote:
Tue Oct 28, 2025 3:32 pm
What is odd is that the regex.h file seems to be in the SDK.
But isn't that because it's part of the C library the Pico SDK uses and links to ?

For me it seems to be at '/usr/include/newlib/regex.h'

And it seems similar for 'picolibc' which is an alternative to 'newlib'.

I would have thought 'regex' would be pure C code so available for anything, not just for POSIX, but I don't know much about these things.

It seems it's available via C++ for RP2040 - viewtopic.php?t=330066

Re: regex

Posted: Tue Oct 28, 2025 11:04 pm
by katak255
One can call it a dark and dusty corner of the toolchain. The user is not expected to pull away the cobwebs and peer around. :D

If you use nm to look in the libc.a of the Arm toolchain, you won't find the regex object files in there. I tried the top level libc.a in the Arm toolchain directory that I have, the object files are not in there. But there is an rpmatch.o that references them, so it really is a very dusty corner... :P To compare, I took the Cygwin libc.a and the regex object files are present.

The C regex header looks like the classic Henry Spencer thingy, see this directory on the newlib mirror:

https://github.com/bminor/newlib/tree/m ... libc/posix

The bulk of the regex implementation is in regcomp.c, and available to compiled programs since it is in libc.a. It just isn't compiled into arm-none-eabi. Presumably adding a standalone Henry Spencer regex source file set (well, everybody uses it as a baseline) into your program, tweak the makefiles, make it non-POSIX usable etc, and the regex stuff that you coded should work the same.

Re: regex

Posted: Wed Oct 29, 2025 5:23 am
by amenjet
Thanks for the replies. I think it might be possible to add the regex code, but it's a bit more work that I'd hoped, and also it uses more memory than I want to allocate to the feature at the moment. I have implemented a more appropriate wildcard system which works for my application, so am OK with no regex for now.

Re: regex

Posted: Wed Oct 29, 2025 1:25 pm
by stevend
amenjet wrote:
Wed Oct 29, 2025 5:23 am
Thanks for the replies. I think it might be possible to add the regex code, but it's a bit more work that I'd hoped, and also it uses more memory than I want to allocate to the feature at the moment.
KISS - regex is a wonderful thing in the right place, but can be a nightmare to get right. It usually leaves me with a headache.

Re: regex

Posted: Wed Oct 29, 2025 2:36 pm
by hippy
KISS - I'd agree with that. It may be worth deciding exactly what 'regex' functionality you actually need. It may be fairly simple to code your own functions to do what is needed.

Re: regex

Posted: Wed Oct 29, 2025 4:58 pm
by amenjet
I've rewritten a Psion Organiser 2 OPL compiler and runtime, and some of the later LZ commands have wildcards, but they are simple * and + wildcards. I thought I'd add regex as well for files name matching but it's just too resource hungry. Also the standard keyboard is a bit limited in characters. No ? for instance...

AltStyle によって変換されたページ (->オリジナル) /