Re: [suse-programming-e] Tips for PCRE expressions?

Trey Gruel <drathos-suse@nightmoose.net> writes:
Secondly, it is almost always a mistake to try to do all your work using a single regex -- use multiple regex's and program logic based on the results.
One of the reasons I'm trying to move things to regex is so the simpler checks can be edited in config files that can be reloaded on the fly.
Have you considered embedding a perl interpreter in your program? Not such overkill if you have a lot of configuration that you would like to be that flexible. (For one regex, it would be overkill though:-)
If this check ends up being a problem, I may end up making an option for a "negative check" where it'll match invalid values. Prolly not a bad idea anyway..
This is what the perl cookbook 2nd edition (page 61) gives for a VALID C float: ^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$ and pcretest seems to like it: markgray@soyo:/ARK/BOOKS/perlcookbook2/ch02> pcretest PCRE version 4.4 21-August-2003 re> /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ data> 123.45 0: 123.45 1: 2: .45 data> -123.45 0: -123.45 1: - 2: .45 data> unkn No match data> NaN No match data> abcdef No match data> +123.456e+02 0: +123.456e+02 1: + 2: .456 3: e+02 4: +02 data>
participants (1)
-
Mark Gray