Pattern: Integer with custom base

“Integer with custom base” is one of the patterns that you can select on the Match panel. Use this pattern to make a field match an integer number in any base between 2 (binary) and 36. Bases 2 to 10 use the digits 0 to 9, up to one less than the base. Bases 11 to 36 use the digits 0 to 9 and the letters A to Z to represent the values 10 to 35 as single digits. You can use the same or a different base between 2 and 36 to specify the ranges of numbers that you want the pattern to match.

This example shows how you can use the “integer with custom base” pattern to look for an integer using base 36 notation that represents a decimal (base 10) value between 42 and 2552. You can find this example as “Pattern: integer with custom base” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample:
    1
    G
    16
    4U
    1YW
    68O
    1Q0Y
  3. On the Match panel, set “begin regex match at” to “start of word”, and set “end regex match at” to “end of word”.
  4. Click the Add First Field button to add field 1.
  5. In the “pattern to match field” drop-down list, select “integer with custom base”.



  6. Set the base to 36.
  7. Turn on “limit the integers to these ranges”.
  8. Set the base to specify ranges to 10.
  9. Enter 42..2552 as the range to limit the integers to.
  10. Set the “field validation mode” to “strict”. This is necessary to make RegexMagic limit the integer range to exactly 42 (written as 16 in base 36) and 2552 (written as 1YW in base 36).
  11. On the Regex panel, select “Python 3.13” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
    \b(?:1y[0-9a-w]|1[0-9a-x][0-9A-Z]|[2-9a-z][0-9A-Z]|1[6-9a-z])\b
    Required options: Case insensitive.
    Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks.
  12. The Samples panel now highlights the base 36 integers between 16 and 1YW:
    1
    G
    16
    4U
    1YW
    68O
    1Q0Y

Related Examples

Reference