We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

9 posts • Page 1 of 1
amenjet
Posts: 43
Joined: Thu Jul 22, 2021 9:30 pm

regex

Tue Oct 28, 2025 10:13 am

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?

katak255
Posts: 916
Joined: Sun Apr 07, 2024 3:29 pm

Re: regex

Tue Oct 28, 2025 11:35 am

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.

amenjet
Posts: 43
Joined: Thu Jul 22, 2021 9:30 pm

Re: regex

Tue Oct 28, 2025 3:32 pm

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.

hippy
Posts: 19831
Joined: Fri Sep 09, 2011 10:34 pm

Re: regex

Tue Oct 28, 2025 5:53 pm

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

katak255
Posts: 916
Joined: Sun Apr 07, 2024 3:29 pm

Re: regex

Tue Oct 28, 2025 11:04 pm

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.

amenjet
Posts: 43
Joined: Thu Jul 22, 2021 9:30 pm

Re: regex

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. I have implemented a more appropriate wildcard system which works for my application, so am OK with no regex for now.

stevend
Posts: 947
Joined: Fri Oct 11, 2013 12:28 pm

Re: regex

Wed Oct 29, 2025 1:25 pm

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.

hippy
Posts: 19831
Joined: Fri Sep 09, 2011 10:34 pm

Re: regex

Wed Oct 29, 2025 2:36 pm

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.

amenjet
Posts: 43
Joined: Thu Jul 22, 2021 9:30 pm

Re: regex

Wed Oct 29, 2025 4:58 pm

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...

9 posts • Page 1 of 1

Return to "SDK"

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