RGXG_NUMBER_RANGE(3)
π RGXG_NUMBER_RANGE π
okay bestie, so you know how librgxg has this whole thing β and this page is from the librgxg manual? yeah. we're talking about rgxg_number_range and rgxg_number_greaterequal today and honestly? they ate. let's go π«Ά
β¨ NAME β¨
so basically there's two of them, and they're besties:
rgxg_number_range,rgxg_number_greaterequalβ they build you a regex that matches integers in the given range. that's the whole job. that's the vibe. π
πΈ SYNOPSIS πΈ
like, here's the tea, literally copy this:
#include <rgxg/number.h>
int rgxg_number_range (long long first, long long last, int base,
size_t min_length, char *regex, rgxg_options_t options);
int rgxg_number_greaterequal (long long number, int base,
size_t min_length, char *regex, rgxg_options_t options);
π¦ DESCRIPTION π¦
okay so first up, rgxg_number_range() β it generates the (extended) regular expression that matches integers in the range between first and last. cute, right? no cap.
then rgxg_number_greaterequal() generates the (extended) regular expression that matches integers greater than or equal to number. so like, "this and everything above it". iconic behaviour honestly.
the base of the matched integers is specified by base, and it must be between 2 and 32 inclusive β that's the law, bestie, don't test it. β οΈ also heads up: for bases greater than 16 the "extended hex" alphabet gets used (it's referenced as 'base32hex' in RFC 4648, iykyk).
now, if RGXG_LEADINGZERO or RGXG_VARLEADINGZERO is set, then min_length specifies the minimum length of the matched integers β otherwise that argument just gets ignored entirely, like it's not even there. for instance the number 5 with min_length set to 3 and options set to RGXG_LEADINGZERO is matched as '005'. slay. by default the number of leading zeros depends on the length of the last number. and if min_length is lesser than or equal to the number of digits of last, the value has no effect. yeah. nothing. zero. π
the generated regular expression gets written to the character string regex, including the terminating null byte ('\0') β unless RGXG_NONULLBYTE is set. and if regex is NULL? then the return value is the number of characters (excluding the terminating null byte) that would have been written in case regex has been initialized. π
β οΈ real talk: note that the functions assume an arbitrarily long regex string, so callers must ensure that the given string is large enough to not overflow the actual space. do not play with this one bestie, fr fr.
options is either zero, or the bitwise-or of one or more of the following macros:
π OPTIONS π
RGXG_NOUPPERCASEβ the generated regular expression only matches lower case letters for base values greater than10. the default is to match both lower and upper case letters.RGXG_NOLOWERCASEβ the generated regular expression only matches upper case letters for base values greater than10. the default is to match both lower and upper case letters.RGXG_NOOUTERPARENSβ omit the outer parenthesis, if any, of the regular expression. bye bye parens πRGXG_LEADINGZEROβ the generated regular expression only matches integers with leading zeros (e.g. the integer5is only matched as'005'). the number of leading zeros is influenced by themin_lengthargument (see above). by default no leading zeros are matched.RGXG_VARLEADINGZEROβ the generated regular expression matches integers with a variable number of leading zeros (e.g. the number5is matched as'5','05'and'005'). the maximum number of leading zeros is influenced by themin_lengthargument (see above). by default no leading zeros are matched.RGXG_NONULLBYTEβ do not add the terminating null byte ('\0') to the regex string.
π¨ note thatRGXG_NOUPPERCASEandRGXG_NOLOWERCASEas well asRGXG_LEADINGZEROandRGXG_VARLEADINGZEROare mutual exclusive options. pick a lane bestie, you cannot have both. π
β RETURN VALUE β
upon successful return, these functions return the number of characters (excluding the terminating null byte) written to regex. periodt.
if an error occurs, a (negative) error code is returned (see ERRORS section). yeah, negative. sad girl hours. π
π ERRORS π
the following errors can be returned:
RGXG_ERROR_RANGE(rgxg_number_range()only) β invalid range (e.g.firstnumber is greater thanlastnumber). make it make sense, bestie.RGXG_ERROR_BASEβ the base is lesser than2or greater than32.RGXG_ERROR_NEGARGβ at least one argument is negative.RGXG_ERROR_ARG2BIG(rgxg_number_greaterequal()only) β the value ofnumberis too large.RGXG_ERROR_MUTEXOPTIONSβ two mutual exclusive options were specified. told you. π
π§ AVAILABILITY π§
these functions are available since rgxg 0.1. vintage. retro. still serving. β¨
π₯ SEE ALSO π₯
regex(7), rgxg_net_cidr_ipv4(3), rgxg_net_cidr_ipv6(3), rgxg_net_cidr_string(3).
go read those too, they're part of the same friend group π
π AUTHOR π
Hannes von Haugwitz <hannes@vonhaugwitz.com>
and that's the whole page babes π this was the librgxg manual, page RGXG_NUMBER_RANGE(3), from rgxg 0.1.2, dated Apr 12, 2020. mwah, go write some regexes, you're gonna do amazing π¦π
π¦ where this page comes from
- debian bookworm: librgxg-dev 0.1.2-5
- debian trixie: librgxg-dev 0.1.2-7
- nixos 26.05: rgxg 0.1.2
- nixpkgs unstable: rgxg 0.1.2
- ubuntu jammy: librgxg-dev 0.1.2-4
- ubuntu noble: librgxg-dev 0.1.2-5
- ubuntu questing: librgxg-dev 0.1.2-7
- ubuntu resolute: librgxg-dev 0.1.2-8
- ubuntu stonking: librgxg-dev 0.1.2-8
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms