1

Is there a "ready way"/library to extract patterns for usage with sprintf() or std::cout from regex patterns?

For regex pattern validation I am using "regex.h"

And storing validating patterns as, for example:

"A((\\+|\\-)(\\d|\\.){6})\\r"
"G((\\+|\\-)(\\d|\\.){6})\\r"

I want to have something like "A+%06f", "G+%06f".

nikolas
  • 8,707
  • 9
  • 50
  • 70
Maquefel
  • 480
  • 4
  • 16
  • 1
    There isn't a way to do this, but for simple cases you can write your own. This answer is on [A+] regexes: http://stackoverflow.com/a/28862668/2642059 – Jonathan Mee Aug 04 '15 at 13:12

1 Answers1

0

The "regex.h" that I am experienced with (some version of GNU libc) seemed to make many memory allocations when a regular expression was build on run-time, rendering it inefficient for simple patterns such as format specifiers, so I doubt any actual C library implementation would use regex.h for the format specifiers, which in turn makes it unlikely that a function such as the one you search for exist.

Also, your regular expressions seem to match strings such as "A+......", which don't match neither of the format specifiers you gave.

  • No, it doesn't "seem to match strings such as "A+......"". And regex.h is POSIX, and not some version of GNU libc. And question was not about existence of such function in libc. – Maquefel Aug 21 '13 at 08:22
  • @Maquefel: `(\d|\.){6}` matches "......", [example](http://regexpal.com/?flags=g&regex=%28\d|\.%29{6}&input=......%201.2345). – Zeta Aug 21 '13 at 08:59
  • @Zeta - yes. If the question is not clear i can clarify. Question is not about matches pattern something or not, it is about a ready library that can recognize (\\+|\\-)\\d{6} in pattern and replace for %+06d for example. If anyone is aware of existence of such lib, he will give information about it. – Maquefel Aug 21 '13 at 09:34