---
name: "rgxg_number_range"
section: "3"
platform: "linux"
package: "librgxg-dev"
version: "0.1.2-7"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rgxg_number_range"
---

# rgxg\_number\_range(3)

create regex that matches integers in the given range

## NAME

rgxg\_number\_range, rgxg\_number\_greaterequal - create regex that matches integers in the given range

## SYNOPSIS

```
#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

**rgxg\_number\_range**() generates the (extended) regular expression that matches integers in the range between *first* and *last*.

**rgxg\_number\_greaterequal**() generates the (extended) regular expression that matches integers greater than or equal to *number*.

The base of the matched integers is specified by *base*, which must be between 2 and 32 inclusive. Note that for bases greater than 16 the "extended hex" alphabet is used (referenced as 'base32hex' in **RFC 4648**).

If **RGXG\_LEADINGZERO** or **RGXG\_VARLEADINGZERO** is set, then *min\_length* specifies the minimum length of the matched integers (otherwise the argument is ignored). For instance the number 5 with *min\_length* set to 3 and options set to **RGXG\_LEADINGZERO** is matched as '005'. By default the number of leading zeros depends on the length of the *last* number. If *min\_length* is lesser than or equal to the number of digits of *last*, the value has no effect.

The generated regular expression is written to the character string *regex*, including the terminating null byte ('\\0'), unless **RGXG\_NONULLBYTE** is set. If *regex* is NULL the return value is the number of characters (excluding the terminating null byte) that would have been written in case *regex* has been initialized. Note that the functions assume an arbitrarily long *regex* string, callers must **ensure** that the given string is large enough to not overflow the actual space.

*options* is either zero, or the bitwise-**or** of one or more of the following macros:

- **RGXG\_NOUPPERCASE**

  The generated regular expression only matches lower case letters for *base* values greater than 10. 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 than 10. The default is to match both lower and upper case letters.

- **RGXG\_NOOUTERPARENS**

  Omit the outer parenthesis, if any, of the regular expression.

- **RGXG\_LEADINGZERO**

  The generated regular expression only matches integers with leading zeros (e.g. the integer 5 is only matched as '005'). The number of leading zeros is influenced by the *min\_length* argument (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 number 5 is matched as '5', '05' and '005'). The maximum number of leading zeros is influenced by the *min\_length* argument (see above). By default no leading zeros are matched.

- **RGXG\_NONULLBYTE**

  Do not add the terminating null byte ('\\0') to the *regex* string.

Note that **RGXG\_NOUPPERCASE** and **RGXG\_NOLOWERCASE** as well as **RGXG\_LEADINGZERO** and **RGXG\_VARLEADINGZERO** are mutual exclusive options.

## RETURN VALUE

Upon successful return, these functions return the number of characters (excluding the terminating null byte) written to *regex*.

If an error occurs, a (negative) error code is returned (see **ERRORS** section).

## ERRORS

The following errors can be returned:

- **RGXG\_ERROR\_RANGE** (**rgxg\_number\_range**() only)

  Invalid range (e.g. *first* number is greater than *last* number).

- **RGXG\_ERROR\_BASE**

  The base is lesser than 2 or greater than 32.

- **RGXG\_ERROR\_NEGARG**

  At least one argument is negative.

- **RGXG\_ERROR\_ARG2BIG** (**rgxg\_number\_greaterequal**() only)

  The value of *number* is too large.

- **RGXG\_ERROR\_MUTEXOPTIONS**

  Two mutual exclusive options were specified.

## AVAILABILITY

These functions are available since rgxg 0.1.

## SEE ALSO

[**regex**(7)](/regex/7.md), [**rgxg\_net\_cidr\_ipv4**(3)](/rgxg_net_cidr_ipv4/3.md), [**rgxg\_net\_cidr\_ipv6**(3)](/rgxg_net_cidr_ipv6/3.md), [**rgxg\_net\_cidr\_string**(3)](/rgxg_net_cidr_string/3.md).

## AUTHOR

Hannes von Haugwitz \<hannes@vonhaugwitz.com\>
