Pattern: Integer with Unicode decimals

“Integer with Unicode decimals” is one of the patterns that you can select on the Match panel. Use this pattern to make a field match an integer number that consists of a single set of Unicode digits from the sets of Unicode digits that you allow the pattern to use. Unicode supports many different ranges of 10 characters that represent the digits 0 to 9 in various different scripts. There are also different representations of the actual digits 0 to 9, such as the full-width digits used in this example.

We’ll generate a regular expression that matches any decimal integer between 42 (the answer to the ultimate question about everything) and 2552 (the year on the Buddhist calendar that saw the release of RegexMagic 1.0). If the numbers look like they’re weirdly spaced, that’s because they are “full-width” characters that are intended to be mixed with and line up properly with ideographs in Chinese, Japanese, or Korean text.

  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 with full-width decimals:
    1
    16
    42
    174
    2552
    8088
    80386
  3. Select the text you just pasted in, and click the Unmark button on the Samples panel. This removes all fields from the Match panel that may be left over from a previous regular expression.
  4. Select the number 42 in the sample text and click the Mark button.
  5. Select the number 2552 in the sample text and click the 1 button. It’s important to use this button instead of the Mark button, because we want to provide an additional sample for the same field instead of adding a new field.
  6. Switch to the Match panel. You’ll notice RegexMagic correctly auto-detected the “integer with Unicode decimals” pattern with the range 42..2552 using the digits “full-width 0..9”.



  7. Click the “limit the integers to these ranges” checkbox to tell RegexMagic we want to use the minimum and maximum values it auto-detected.
  8. Set the “field validation mode” to “strict”. This is necessary to make RegexMagic limit the integer between the minimum and maximum values exactly, instead of merely restricting the number of digits. Selecting “average” or “strict” is also necessary to avoid matching numbers that mix decimals from different scripts when allowing the pattern to use multiple ranges.
  9. 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(?:255[0-2]|25[0-4][0-9]|2[0-4][0-9]{2}|1[0-9]{3}|[1-9][0-9]{2}|[5-9][0-9]|4[2-9])\b
    Unused options: Case sensitive; Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks.
  10. The Samples panel now highlights the integers between 42 and 2552:
    1
    16
    42
    174
    2552
    8088
    80386

Related Examples

Reference