LoginSignup
3
3

More than 5 years have passed since last update.

正規表現の \w, \d で実際に検出できる文字を探してみた。

Last updated at Posted at 2017-10-25
using System.Linq;

static class Program
{
    static System.Collections.Generic.IEnumerable<char> charlist(string pattern)
    {
        var c = (char)0;
        do
        {
            if (System.Text.RegularExpressions.Regex.IsMatch("" + c, pattern))
            yield return c;
        } while (++c != 0);
    }

    static void Main(string[] args)
    {
        var digits = charlist(@"\d").ToArray();

        System.Diagnostics.Debug.WriteLine(string.Format("{0} chars.", digits.Length));
        System.Diagnostics.Debug.WriteLine(string.Join(",", digits));

        var wordchars = charlist(@"\w").ToArray();

        System.Diagnostics.Debug.WriteLine(string.Format("{0} chars.", wordchars.Length));
        System.Diagnostics.Debug.WriteLine(string.Join(",", wordchars));
    }
}
370 chars.
0,1,2,3,4,5,6,7,8,9,٠,١,٢,٣,٤,٥,٦,٧,٨,٩,۰,۱,۲,۳,۴,۵,۶,۷,۸,۹,߀,߁,߂,߃,߄,߅,߆,߇,߈,߉,०,१,२,३,४,५,६,७,८,९,০,১,২,৩,৪,৫,৬,৭,৮,৯,੦,੧,੨,੩,੪,੫,੬,੭,੮,੯,૦,૧,૨,૩,૪,૫,૬,૭,૮,૯,୦,୧,୨,୩,୪,୫,୬,୭,୮,୯,௦,௧,௨,௩,௪,௫,௬,௭,௮,௯,౦,౧,౨,౩,౪,౫,౬,౭,౮,౯,೦,೧,೨,೩,೪,೫,೬,೭,೮,೯,൦,൧,൨,൩,൪,൫,൬,൭,൮,൯,෦,෧,෨,෩,෪,෫,෬,෭,෮,෯,๐,๑,๒,๓,๔,๕,๖,๗,๘,๙,໐,໑,໒,໓,໔,໕,໖,໗,໘,໙,༠,༡,༢,༣,༤,༥,༦,༧,༨,༩,၀,၁,၂,၃,၄,၅,၆,၇,၈,၉,႐,႑,႒,႓,႔,႕,႖,႗,႘,႙,០,១,២,៣,៤,៥,៦,៧,៨,៩,᠐,᠑,᠒,᠓,᠔,᠕,᠖,᠗,᠘,᠙,᥆,᥇,᥈,᥉,᥊,᥋,᥌,᥍,᥎,᥏,᧐,᧑,᧒,᧓,᧔,᧕,᧖,᧗,᧘,᧙,᪀,᪁,᪂,᪃,᪄,᪅,᪆,᪇,᪈,᪉,᪐,᪑,᪒,᪓,᪔,᪕,᪖,᪗,᪘,᪙,᭐,᭑,᭒,᭓,᭔,᭕,᭖,᭗,᭘,᭙,᮰,᮱,᮲,᮳,᮴,᮵,᮶,᮷,᮸,᮹,᱀,᱁,᱂,᱃,᱄,᱅,᱆,᱇,᱈,᱉,᱐,᱑,᱒,᱓,᱔,᱕,᱖,᱗,᱘,᱙,꘠,꘡,꘢,꘣,꘤,꘥,꘦,꘧,꘨,꘩,꣐,꣑,꣒,꣓,꣔,꣕,꣖,꣗,꣘,꣙,꤀,꤁,꤂,꤃,꤄,꤅,꤆,꤇,꤈,꤉,꧐,꧑,꧒,꧓,꧔,꧕,꧖,꧗,꧘,꧙,꧰,꧱,꧲,꧳,꧴,꧵,꧶,꧷,꧸,꧹,꩐,꩑,꩒,꩓,꩔,꩕,꩖,꩗,꩘,꩙,꯰,꯱,꯲,꯳,꯴,꯵,꯶,꯷,꯸,꯹,0,1,2,3,4,5,6,7,8,9
50086 chars.
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,---割愛---
プログラム '[9276] ConsoleApp1.exe' はコード 0 (0x0) で終了しました。

"\w" は "[_0-9a-zA-Z]" 相当だと思っていたので、ちょっとびっくり。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3