1295
votes

I made a comment yesterday on an answer where someone had used [0123456789] in a regex rather than [0-9] or \d. I said it was probably more efficient to use a range or digit specifier than a character set.

I decided to test that out today and found out to my surprise that (in the c# regex engine at least) \d appears to be less efficient than either of the other two which don't seem to differ much. Here is my test output over 10000 random strings of 1000 random characters with 5077 actually containing a digit:

Regex \d           took 00:00:00.2141226 result: 5077/10000
Regex [0-9]        took 00:00:00.1357972 result: 5077/10000  63.42 % of first
Regex [0123456789] took 00:00:00.1388997 result: 5077/10000  64.87 % of first

It's a surprise to me for two reasons, that I would be interested if anyone can shed some light on:

  1. I would have thought the range would be implemented much more efficiently than the set.
  2. I can't understand why \d is worse than [0-9]. Is there more to \d than simply shorthand for [0-9]?

Here is the test code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace SO_RegexPerformance
{
    class Program
    {
        static void Main(string[] args)
        {
            var rand = new Random(1234);
            var strings = new List<string>();
            //10K random strings
            for (var i = 0; i < 10000; i++)
            {
                //generate random string
                var sb = new StringBuilder();
                for (var c = 0; c < 1000; c++)
                {
                    //add a-z randomly
                    sb.Append((char)('a' + rand.Next(26)));
                }
                //in roughly 50% of them, put a digit
                if (rand.Next(2) == 0)
                {
                    //replace 1 char with a digit 0-9
                    sb[rand.Next(sb.Length)] = (char)('0' + rand.Next(10));
                }
                strings.Add(sb.ToString());
            }

            var baseTime = testPerfomance(strings, @"\d");
            Console.WriteLine();
            var testTime = testPerfomance(strings, "[0-9]");
            Console.WriteLine("  {0:P2} of first", testTime.TotalMilliseconds / baseTime.TotalMilliseconds);
            testTime = testPerfomance(strings, "[0123456789]");
            Console.WriteLine("  {0:P2} of first", testTime.TotalMilliseconds / baseTime.TotalMilliseconds);
        }

        private static TimeSpan testPerfomance(List<string> strings, string regex)
        {
            var sw = new Stopwatch();

            int successes = 0;

            var rex = new Regex(regex);

            sw.Start();
            foreach (var str in strings)
            {
                if (rex.Match(str).Success)
                {
                    successes++;
                }
            }
            sw.Stop();

            Console.Write("Regex {0,-12} took {1} result: {2}/{3}", regex, sw.Elapsed, successes, strings.Count);

            return sw.Elapsed;
        }
    }
}
5
Maybe \d deals with locales. E.g. Hebrew uses letters for digits. - Barmar
This is an interesting question precisely because \d does not mean the same thing in different languages. In Java, for example \d does indeed match 0-9 only - Ray Toal
@Barmar Hebrew does not use letters for digits normally, rather the same latin numeral digits [0-9]. Letters can be substituted for digits, but this is a rare use and reserved for special terms. I would not expect a regex parser to match כ"ג יורדי סירה (with כ"ג being a substitue for 23). Also, as can be seen in Sina Iravanian's answer, Hebrew letters do not appear as valid matches for \d. - Yuval Adam
Porting weston's code to Java yields: -- Regex \d took 00:00:00.043922 result: 4912/10000 -- Regex [0-9] took 00:00:00.073658 result: 4912/10000 167% of first -- Regex [0123456789] took 00:00:00.085799 result: 4912/10000 195% of first - Lunchbox

5 Answers

1606
votes

\d checks all Unicode digits, while [0-9] is limited to these 10 characters. For example, Persian digits, ۱۲۳۴۵۶۷۸۹, are an example of Unicode digits which are matched with \d, but not [0-9].

You can generate a list of all such characters using the following code:

var sb = new StringBuilder();
for(UInt16 i = 0; i < UInt16.MaxValue; i++)
{
    string str = Convert.ToChar(i).ToString();
    if (Regex.IsMatch(str, @"\d"))
        sb.Append(str);
}
Console.WriteLine(sb.ToString());

Which generates:

0123456789٠١٢٣٤٥٦٧٨٩۰۱۲۳۴۵۶۷۸۹߀߁߂߃߄߅߆߇߈߉०१२३४५६७८९০১২৩৪৫৬৭৮৯੦੧੨੩੪੫੬੭੮੯૦૧૨૩૪૫૬૭૮૯୦୧୨୩୪୫୬୭୮୯௦௧௨௩௪௫௬௭௮௯౦౧౨౩౪౫౬౭౮౯೦೧೨೩೪೫೬೭೮೯൦൧൨൩൪൫൬൭൮൯๐๑๒๓๔๕๖๗๘๙໐໑໒໓໔໕໖໗໘໙༠༡༢༣༤༥༦༧༨༩၀၁၂၃၄၅၆၇၈၉႐႑႒႓႔႕႖႗႘႙០១២៣៤៥៦៧៨៩᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙᥆᥇᥈᥉᥊᥋᥌᥍᥎᥏᧐᧑᧒᧓᧔᧕᧖᧗᧘᧙᭐᭑᭒᭓᭔᭕᭖᭗᭘᭙᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹᱀᱁᱂᱃᱄᱅᱆᱇᱈᱉᱐᱑᱒᱓᱔᱕᱖᱗᱘᱙꘠꘡꘢꘣꘤꘥꘦꘧꘨꘩꣐꣑꣒꣓꣔꣕꣖꣗꣘꣙꤀꤁꤂꤃꤄꤅꤆꤇꤈꤉꩐꩑꩒꩓꩔꩕꩖꩗꩘꩙0123456789

277
votes

Credit to ByteBlast for noticing this in the docs. Just changing the regex constructor:

var rex = new Regex(regex, RegexOptions.ECMAScript);

Gives new timings:

Regex \d           took 00:00:00.1355787 result: 5077/10000
Regex [0-9]        took 00:00:00.1360403 result: 5077/10000  100.34 % of first
Regex [0123456789] took 00:00:00.1362112 result: 5077/10000  100.47 % of first
122
votes

From Does “\d” in regex mean a digit?:

[0-9] isn't equivalent to \d. [0-9] matches only 0123456789 characters, while \d matches [0-9] and other digit characters, for example Eastern Arabic numerals ٠١٢٣٤٥٦٧٨٩

20
votes

An addition to top answer from Sina Iravianian, here is a .NET 4.5 version (since only that version supports UTF16 output, c.f. the first three lines) of his code, using the full range of Unicode code points. Due to the lack of proper support for higher Unicode planes, many people are not aware of always checking for and including the upper Unicode planes. Nevertheless they sometimes do contain some important characters.

Update

Since \d does not support non-BMP characters in regex (thanks xanatos), here a version that uses the Unicode character database

Update 2

Thanks to damilola-adegunwa, I have added the missing reference to the UCD (via NuGet package UnicodeInformation). Also udpated to the latest .NET core version and UTF-8 output.

// reference https://www.nuget.org/packages/UnicodeInformation/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Unicode;
                    
public class Program
{
    public static void Main()
    {
        var unicodeEncoding = new UTF8Encoding(false);
        Console.OutputEncoding = unicodeEncoding;

        var numberCategories = new HashSet<UnicodeCategory>(new []{
            UnicodeCategory.DecimalDigitNumber,
            UnicodeCategory.LetterNumber,
            UnicodeCategory.OtherNumber
        });
        var numberLikeChars =
            from codePoint in Enumerable.Range(0, 0x10ffff)
            where codePoint > UInt16.MaxValue 
                || (!char.IsLowSurrogate((char) codePoint) && !char.IsHighSurrogate((char) codePoint))
            let charInfo = UnicodeInfo.GetCharInfo(codePoint)
            where numberCategories.Contains(charInfo.Category)
            let codePointString = char.ConvertFromUtf32(codePoint)
            select (codePoint, charInfo, codePointString);

        foreach (var (codePoint, charInfo, codePointString) in numberLikeChars)
        {
            Console.Write("U+{0} ", codePoint.ToString("X6"));
            Console.Write(" {0,-4}", codePointString);
            Console.Write(" {0,-40}", charInfo.Name ?? charInfo.OldName);
            Console.Write(" {0,-6}", CharUnicodeInfo.GetNumericValue(codePointString, 0));
            Console.Write(" {0,-6}", CharUnicodeInfo.GetDigitValue(codePointString, 0));
            Console.Write(" {0,-6}", CharUnicodeInfo.GetDecimalDigitValue(codePointString, 0));
            Console.WriteLine(" {0}", charInfo.Category);
        }
    }
}

Yielding the following output:

U+000030  0    DIGIT ZERO                               0      0      0      DecimalDigitNumber
U+000031  1    DIGIT ONE                                1      1      1      DecimalDigitNumber
U+000032  2    DIGIT TWO                                2      2      2      DecimalDigitNumber
U+000033  3    DIGIT THREE                              3      3      3      DecimalDigitNumber
U+000034  4    DIGIT FOUR                               4      4      4      DecimalDigitNumber
U+000035  5    DIGIT FIVE                               5      5      5      DecimalDigitNumber
U+000036  6    DIGIT SIX                                6      6      6      DecimalDigitNumber
U+000037  7    DIGIT SEVEN                              7      7      7      DecimalDigitNumber
U+000038  8    DIGIT EIGHT                              8      8      8      DecimalDigitNumber
U+000039  9    DIGIT NINE                               9      9      9      DecimalDigitNumber
U+0000B2  ²    SUPERSCRIPT TWO                          2      2      -1     OtherNumber
U+0000B3  ³    SUPERSCRIPT THREE                        3      3      -1     OtherNumber
U+0000B9  ¹    SUPERSCRIPT ONE                          1      1      -1     OtherNumber
U+0000BC  ¼    VULGAR FRACTION ONE QUARTER              0.25   -1     -1     OtherNumber
U+0000BD  ½    VULGAR FRACTION ONE HALF                 0.5    -1     -1     OtherNumber
U+0000BE  ¾    VULGAR FRACTION THREE QUARTERS           0.75   -1     -1     OtherNumber
U+000660  ٠    ARABIC-INDIC DIGIT ZERO                  0      0      0      DecimalDigitNumber
U+000661  ١    ARABIC-INDIC DIGIT ONE                   1      1      1      DecimalDigitNumber
U+000662  ٢    ARABIC-INDIC DIGIT TWO                   2      2      2      DecimalDigitNumber
U+000663  ٣    ARABIC-INDIC DIGIT THREE                 3      3      3      DecimalDigitNumber
U+000664  ٤    ARABIC-INDIC DIGIT FOUR                  4      4      4      DecimalDigitNumber
U+000665  ٥    ARABIC-INDIC DIGIT FIVE                  5      5      5      DecimalDigitNumber
U+000666  ٦    ARABIC-INDIC DIGIT SIX                   6      6      6      DecimalDigitNumber
U+000667  ٧    ARABIC-INDIC DIGIT SEVEN                 7      7      7      DecimalDigitNumber
U+000668  ٨    ARABIC-INDIC DIGIT EIGHT                 8      8      8      DecimalDigitNumber
U+000669  ٩    ARABIC-INDIC DIGIT NINE                  9      9      9      DecimalDigitNumber
U+0006F0  ۰    EXTENDED ARABIC-INDIC DIGIT ZERO         0      0      0      DecimalDigitNumber
U+0006F1  ۱    EXTENDED ARABIC-INDIC DIGIT ONE          1      1      1      DecimalDigitNumber
U+0006F2  ۲    EXTENDED ARABIC-INDIC DIGIT TWO          2      2      2      DecimalDigitNumber
U+0006F3  ۳    EXTENDED ARABIC-INDIC DIGIT THREE        3      3      3      DecimalDigitNumber
U+0006F4  ۴    EXTENDED ARABIC-INDIC DIGIT FOUR         4      4      4      DecimalDigitNumber
U+0006F5  ۵    EXTENDED ARABIC-INDIC DIGIT FIVE         5      5      5      DecimalDigitNumber
U+0006F6  ۶    EXTENDED ARABIC-INDIC DIGIT SIX          6      6      6      DecimalDigitNumber
U+0006F7  ۷    EXTENDED ARABIC-INDIC DIGIT SEVEN        7      7      7      DecimalDigitNumber
U+0006F8  ۸    EXTENDED ARABIC-INDIC DIGIT EIGHT        8      8      8      DecimalDigitNumber
U+0006F9  ۹    EXTENDED ARABIC-INDIC DIGIT NINE         9      9      9      DecimalDigitNumber
U+0007C0  ߀    NKO DIGIT ZERO                           0      0      0      DecimalDigitNumber
U+0007C1  ߁    NKO DIGIT ONE                            1      1      1      DecimalDigitNumber
U+0007C2  ߂    NKO DIGIT TWO                            2      2      2      DecimalDigitNumber
U+0007C3  ߃    NKO DIGIT THREE                          3      3      3      DecimalDigitNumber
U+0007C4  ߄    NKO DIGIT FOUR                           4      4      4      DecimalDigitNumber
U+0007C5  ߅    NKO DIGIT FIVE                           5      5      5      DecimalDigitNumber
U+0007C6  ߆    NKO DIGIT SIX                            6      6      6      DecimalDigitNumber
U+0007C7  ߇    NKO DIGIT SEVEN                          7      7      7      DecimalDigitNumber
U+0007C8  ߈    NKO DIGIT EIGHT                          8      8      8      DecimalDigitNumber
U+0007C9  ߉    NKO DIGIT NINE                           9      9      9      DecimalDigitNumber
U+000966      DEVANAGARI DIGIT ZERO                    0      0      0      DecimalDigitNumber
U+000967      DEVANAGARI DIGIT ONE                     1      1      1      DecimalDigitNumber
U+000968      DEVANAGARI DIGIT TWO                     2      2      2      DecimalDigitNumber
U+000969      DEVANAGARI DIGIT THREE                   3      3      3      DecimalDigitNumber
U+00096A      DEVANAGARI DIGIT FOUR                    4      4      4      DecimalDigitNumber
U+00096B      DEVANAGARI DIGIT FIVE                    5      5      5      DecimalDigitNumber
U+00096C      DEVANAGARI DIGIT SIX                     6      6      6      DecimalDigitNumber
U+00096D      DEVANAGARI DIGIT SEVEN                   7      7      7      DecimalDigitNumber
U+00096E      DEVANAGARI DIGIT EIGHT                   8      8      8      DecimalDigitNumber
U+00096F      DEVANAGARI DIGIT NINE                    9      9      9      DecimalDigitNumber
U+0009E6      BENGALI DIGIT ZERO                       0      0      0      DecimalDigitNumber
U+0009E7      BENGALI DIGIT ONE                        1      1      1      DecimalDigitNumber
U+0009E8      BENGALI DIGIT TWO                        2      2      2      DecimalDigitNumber
U+0009E9      BENGALI DIGIT THREE                      3      3      3      DecimalDigitNumber
U+0009EA      BENGALI DIGIT FOUR                       4      4      4      DecimalDigitNumber
U+0009EB      BENGALI DIGIT FIVE                       5      5      5      DecimalDigitNumber
U+0009EC      BENGALI DIGIT SIX                        6      6      6      DecimalDigitNumber
U+0009ED      BENGALI DIGIT SEVEN                      7      7      7      DecimalDigitNumber
U+0009EE      BENGALI DIGIT EIGHT                      8      8      8      DecimalDigitNumber
U+0009EF      BENGALI DIGIT NINE                       9      9      9      DecimalDigitNumber
U+0009F4      BENGALI CURRENCY NUMERATOR ONE           0.0625 -1     -1     OtherNumber
U+0009F5      BENGALI CURRENCY NUMERATOR TWO           0.125  -1     -1     OtherNumber
U+0009F6      BENGALI CURRENCY NUMERATOR THREE         0.1875 -1     -1     OtherNumber
U+0009F7      BENGALI CURRENCY NUMERATOR FOUR          0.25   -1     -1     OtherNumber
U+0009F8      BENGALI CURRENCY NUMERATOR ONE LESS THAN THE DENOMINATOR 0.75   -1     -1     OtherNumber
U+0009F9      BENGALI CURRENCY DENOMINATOR SIXTEEN     16     -1     -1     OtherNumber
U+000A66      GURMUKHI DIGIT ZERO                      0      0      0      DecimalDigitNumber
U+000A67      GURMUKHI DIGIT ONE                       1      1      1      DecimalDigitNumber
U+000A68      GURMUKHI DIGIT TWO                       2      2      2      DecimalDigitNumber
U+000A69      GURMUKHI DIGIT THREE                     3      3      3      DecimalDigitNumber
U+000A6A      GURMUKHI DIGIT FOUR                      4      4      4      DecimalDigitNumber
U+000A6B      GURMUKHI DIGIT FIVE                      5      5      5      DecimalDigitNumber
U+000A6C      GURMUKHI DIGIT SIX                       6      6      6      DecimalDigitNumber
U+000A6D      GURMUKHI DIGIT SEVEN                     7      7      7      DecimalDigitNumber
U+000A6E      GURMUKHI DIGIT EIGHT                     8      8      8      DecimalDigitNumber
U+000A6F      GURMUKHI DIGIT NINE                      9      9      9      DecimalDigitNumber
U+000AE6      GUJARATI DIGIT ZERO                      0      0      0      DecimalDigitNumber
U+000AE7      GUJARATI DIGIT ONE                       1      1      1      DecimalDigitNumber
U+000AE8      GUJARATI DIGIT TWO                       2      2      2      DecimalDigitNumber
U+000AE9      GUJARATI DIGIT THREE                     3      3      3      DecimalDigitNumber
U+000AEA      GUJARATI DIGIT FOUR                      4      4      4      DecimalDigitNumber
U+000AEB      GUJARATI DIGIT FIVE                      5      5      5      DecimalDigitNumber
U+000AEC      GUJARATI DIGIT SIX                       6      6      6      DecimalDigitNumber
U+000AED      GUJARATI DIGIT SEVEN                     7      7      7      DecimalDigitNumber
U+000AEE      GUJARATI DIGIT EIGHT                     8      8      8      DecimalDigitNumber
U+000AEF      GUJARATI DIGIT NINE                      9      9      9      DecimalDigitNumber
U+000B66      ORIYA DIGIT ZERO                         0      0      0      DecimalDigitNumber
U+000B67      ORIYA DIGIT ONE                          1      1      1      DecimalDigitNumber
U+000B68      ORIYA DIGIT TWO                          2      2      2      DecimalDigitNumber
U+000B69      ORIYA DIGIT THREE                        3      3      3      DecimalDigitNumber
U+000B6A      ORIYA DIGIT FOUR                         4      4      4      DecimalDigitNumber
U+000B6B      ORIYA DIGIT FIVE                         5      5      5      DecimalDigitNumber
U+000B6C      ORIYA DIGIT SIX                          6      6      6      DecimalDigitNumber
U+000B6D      ORIYA DIGIT SEVEN                        7      7      7      DecimalDigitNumber
U+000B6E      ORIYA DIGIT EIGHT                        8      8      8      DecimalDigitNumber
U+000B6F      ORIYA DIGIT NINE                         9      9      9      DecimalDigitNumber
U+000B72      ORIYA FRACTION ONE QUARTER               0.25   -1     -1     OtherNumber
U+000B73      ORIYA FRACTION ONE HALF                  0.5    -1     -1     OtherNumber
U+000B74      ORIYA FRACTION THREE QUARTERS            0.75   -1     -1     OtherNumber
U+000B75      ORIYA FRACTION ONE SIXTEENTH             0.0625 -1     -1     OtherNumber
U+000B76      ORIYA FRACTION ONE EIGHTH                0.125  -1     -1     OtherNumber
U+000B77      ORIYA FRACTION THREE SIXTEENTHS          0.1875 -1     -1     OtherNumber
U+000BE6      TAMIL DIGIT ZERO                         0      0      0      DecimalDigitNumber
U+000BE7      TAMIL DIGIT ONE                          1      1      1      DecimalDigitNumber
U+000BE8      TAMIL DIGIT TWO                          2      2      2      DecimalDigitNumber
U+000BE9      TAMIL DIGIT THREE                        3      3      3      DecimalDigitNumber
U+000BEA      TAMIL DIGIT FOUR                         4      4      4      DecimalDigitNumber
U+000BEB      TAMIL DIGIT FIVE                         5      5      5      DecimalDigitNumber
U+000BEC      TAMIL DIGIT SIX                          6      6      6      DecimalDigitNumber
U+000BED      TAMIL DIGIT SEVEN                        7      7      7      DecimalDigitNumber
U+000BEE      TAMIL DIGIT EIGHT                        8      8      8      DecimalDigitNumber
U+000BEF      TAMIL DIGIT NINE                         9      9      9      DecimalDigitNumber
U+000BF0      TAMIL NUMBER TEN                         10     -1     -1     OtherNumber
U+000BF1      TAMIL NUMBER ONE HUNDRED                 100    -1     -1     OtherNumber
U+000BF2      TAMIL NUMBER ONE THOUSAND                1000   -1     -1     OtherNumber
U+000C66      TELUGU DIGIT ZERO                        0      0      0      DecimalDigitNumber
U+000C67      TELUGU DIGIT ONE                         1      1      1      DecimalDigitNumber
U+000C68      TELUGU DIGIT TWO                         2      2      2      DecimalDigitNumber
U+000C69      TELUGU DIGIT THREE                       3      3      3      DecimalDigitNumber
U+000C6A      TELUGU DIGIT FOUR                        4      4      4      DecimalDigitNumber
U+000C6B      TELUGU DIGIT FIVE                        5      5      5      DecimalDigitNumber
U+000C6C      TELUGU DIGIT SIX                         6      6      6      DecimalDigitNumber
U+000C6D      TELUGU DIGIT SEVEN                       7      7      7      DecimalDigitNumber
U+000C6E      TELUGU DIGIT EIGHT                       8      8      8      DecimalDigitNumber
U+000C6F      TELUGU DIGIT NINE                        9      9      9      DecimalDigitNumber
U+000C78      TELUGU FRACTION DIGIT ZERO FOR ODD POWERS OF FOUR 0      -1     -1     OtherNumber
U+000C79      TELUGU FRACTION DIGIT ONE FOR ODD POWERS OF FOUR 1      -1     -1     OtherNumber
U+000C7A      TELUGU FRACTION DIGIT TWO FOR ODD POWERS OF FOUR 2      -1     -1     OtherNumber
U+000C7B      TELUGU FRACTION DIGIT THREE FOR ODD POWERS OF FOUR 3      -1     -1     OtherNumber
U+000C7C      TELUGU FRACTION DIGIT ONE FOR EVEN POWERS OF FOUR 1      -1     -1     OtherNumber
U+000C7D      TELUGU FRACTION DIGIT TWO FOR EVEN POWERS OF FOUR 2      -1     -1     OtherNumber
U+000C7E      TELUGU FRACTION DIGIT THREE FOR EVEN POWERS OF FOUR 3      -1     -1     OtherNumber
U+000CE6      KANNADA DIGIT ZERO                       0      0      0      DecimalDigitNumber
U+000CE7      KANNADA DIGIT ONE                        1      1      1      DecimalDigitNumber
U+000CE8      KANNADA DIGIT TWO                        2      2      2      DecimalDigitNumber
U+000CE9      KANNADA DIGIT THREE                      3      3      3      DecimalDigitNumber
U+000CEA      KANNADA DIGIT FOUR                       4      4      4      DecimalDigitNumber
U+000CEB      KANNADA DIGIT FIVE                       5      5      5      DecimalDigitNumber
U+000CEC      KANNADA DIGIT SIX                        6      6      6      DecimalDigitNumber
U+000CED      KANNADA DIGIT SEVEN                      7      7      7      DecimalDigitNumber
U+000CEE      KANNADA DIGIT EIGHT                      8      8      8      DecimalDigitNumber
U+000CEF      KANNADA DIGIT NINE                       9      9      9      DecimalDigitNumber
U+000D58      MALAYALAM FRACTION ONE ONE-HUNDRED-AND-SIXTIETH 0.00625 -1     -1     OtherNumber
U+000D59      MALAYALAM FRACTION ONE FORTIETH          0.025  -1     -1     OtherNumber
U+000D5A      MALAYALAM FRACTION THREE EIGHTIETHS      0.0375 -1     -1     OtherNumber
U+000D5B      MALAYALAM FRACTION ONE TWENTIETH         0.05   -1     -1     OtherNumber
U+000D5C      MALAYALAM FRACTION ONE TENTH             0.1    -1     -1     OtherNumber
U+000D5D      MALAYALAM FRACTION THREE TWENTIETHS      0.15   -1     -1     OtherNumber
U+000D5E      MALAYALAM FRACTION ONE FIFTH             0.2    -1     -1     OtherNumber
U+000D66      MALAYALAM DIGIT ZERO                     0      0      0      DecimalDigitNumber
U+000D67      MALAYALAM DIGIT ONE                      1      1      1      DecimalDigitNumber
U+000D68      MALAYALAM DIGIT TWO                      2      2      2      DecimalDigitNumber
U+000D69      MALAYALAM DIGIT THREE                    3      3      3      DecimalDigitNumber
U+000D6A      MALAYALAM DIGIT FOUR                     4      4      4      DecimalDigitNumber
U+000D6B      MALAYALAM DIGIT FIVE                     5      5      5      DecimalDigitNumber
U+000D6C      MALAYALAM DIGIT SIX                      6      6      6      DecimalDigitNumber
U+000D6D      MALAYALAM DIGIT SEVEN                    7      7      7      DecimalDigitNumber
U+000D6E      MALAYALAM DIGIT EIGHT                    8      8      8      DecimalDigitNumber
U+000D6F      MALAYALAM DIGIT NINE                     9      9      9      DecimalDigitNumber
U+000D70      MALAYALAM NUMBER TEN                     10     -1     -1     OtherNumber
U+000D71      MALAYALAM NUMBER ONE HUNDRED             100    -1     -1     OtherNumber
U+000D72      MALAYALAM NUMBER ONE THOUSAND            1000   -1     -1     OtherNumber
U+000D73      MALAYALAM FRACTION ONE QUARTER           0.25   -1     -1     OtherNumber
U+000D74      MALAYALAM FRACTION ONE HALF              0.5    -1     -1     OtherNumber
U+000D75      MALAYALAM FRACTION THREE QUARTERS        0.75   -1     -1     OtherNumber
U+000D76      MALAYALAM FRACTION ONE SIXTEENTH         0.0625 -1     -1     OtherNumber
U+000D77      MALAYALAM FRACTION ONE EIGHTH            0.125  -1     -1     OtherNumber
U+000D78      MALAYALAM FRACTION THREE SIXTEENTHS      0.1875 -1     -1     OtherNumber
U+000DE6      SINHALA LITH DIGIT ZERO                  0      0      0      DecimalDigitNumber
U+000DE7      SINHALA LITH DIGIT ONE                   1      1      1      DecimalDigitNumber
U+000DE8      SINHALA LITH DIGIT TWO                   2      2      2      DecimalDigitNumber
U+000DE9      SINHALA LITH DIGIT THREE                 3      3      3      DecimalDigitNumber
U+000DEA      SINHALA LITH DIGIT FOUR                  4      4      4      DecimalDigitNumber
U+000DEB      SINHALA LITH DIGIT FIVE                  5      5      5      DecimalDigitNumber
U+000DEC      SINHALA LITH DIGIT SIX                   6      6      6      DecimalDigitNumber
U+000DED      SINHALA LITH DIGIT SEVEN                 7      7      7      DecimalDigitNumber
U+000DEE      SINHALA LITH DIGIT EIGHT                 8      8      8      DecimalDigitNumber
U+000DEF      SINHALA LITH DIGIT NINE                  9      9      9      DecimalDigitNumber
U+000E50      THAI DIGIT ZERO                          0      0      0      DecimalDigitNumber
U+000E51      THAI DIGIT ONE                           1      1      1      DecimalDigitNumber
U+000E52      THAI DIGIT TWO                           2      2      2      DecimalDigitNumber
U+000E53      THAI DIGIT THREE                         3      3      3      DecimalDigitNumber
U+000E54      THAI DIGIT FOUR                          4      4      4      DecimalDigitNumber
U+000E55      THAI DIGIT FIVE                          5      5      5      DecimalDigitNumber
U+000E56      THAI DIGIT SIX                           6      6      6      DecimalDigitNumber
U+000E57      THAI DIGIT SEVEN                         7      7      7      DecimalDigitNumber
U+000E58      THAI DIGIT EIGHT                         8      8      8      DecimalDigitNumber
U+000E59      THAI DIGIT NINE                          9      9      9      DecimalDigitNumber
U+000ED0      LAO DIGIT ZERO                           0      0      0      DecimalDigitNumber
U+000ED1      LAO DIGIT ONE                            1      1      1      DecimalDigitNumber
U+000ED2      LAO DIGIT TWO                            2      2      2      DecimalDigitNumber
U+000ED3      LAO DIGIT THREE                          3      3      3      DecimalDigitNumber
U+000ED4      LAO DIGIT FOUR                           4      4      4      DecimalDigitNumber
U+000ED5      LAO DIGIT FIVE                           5      5      5      DecimalDigitNumber
U+000ED6      LAO DIGIT SIX                            6      6      6      DecimalDigitNumber
U+000ED7      LAO DIGIT SEVEN                          7      7      7      DecimalDigitNumber
U+000ED8      LAO DIGIT EIGHT                          8      8      8      DecimalDigitNumber
U+000ED9      LAO DIGIT NINE                           9      9      9      DecimalDigitNumber
...
U+01F10B  🄋   DINGBAT CIRCLED SANS-SERIF DIGIT ZERO    0      -1     -1     OtherNumber
U+01F10C  🄌   DINGBAT NEGATIVE CIRCLED SANS-SERIF DIGIT ZERO 0      -1     -1     OtherNumber
U+01FBF0  🯰   SEGMENTED DIGIT ZERO                     -1     -1     -1     DecimalDigitNumber
U+01FBF1  🯱   SEGMENTED DIGIT ONE                      -1     -1     -1     DecimalDigitNumber
U+01FBF2  🯲   SEGMENTED DIGIT TWO                      -1     -1     -1     DecimalDigitNumber
U+01FBF3  🯳   SEGMENTED DIGIT THREE                    -1     -1     -1     DecimalDigitNumber
U+01FBF4  🯴   SEGMENTED DIGIT FOUR                     -1     -1     -1     DecimalDigitNumber
U+01FBF5  🯵   SEGMENTED DIGIT FIVE                     -1     -1     -1     DecimalDigitNumber
U+01FBF6  🯶   SEGMENTED DIGIT SIX                      -1     -1     -1     DecimalDigitNumber
U+01FBF7  🯷   SEGMENTED DIGIT SEVEN                    -1     -1     -1     DecimalDigitNumber
U+01FBF8  🯸   SEGMENTED DIGIT EIGHT                    -1     -1     -1     DecimalDigitNumber
U+01FBF9  🯹   SEGMENTED DIGIT NINE                     -1     -1     -1     DecimalDigitNumber
0
votes

\d checks all Unicode, while [0-9] is limited to these 10 characters. If just 10 digits, you should use. Others I recommend using \d,Because writing less.