コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【C#】glob によるパターンマッチングを行う方法

はじめに

GitHub で公開されている上記のライブラリを使用すると
C# で glob によるパターンマッチングができるようになる

使用例

static クラスを使用する方法

var isMatch = Glob.IsMatch
(
    input: "Assets/Textures/example.png",
    pattern: "Assets/Textures/*.png"
);

Console.WriteLine( isMatch );

Glob クラスのインスタンスを使用する方法

var glob    = new Glob( "Assets/Textures/*.png" );
var isMatch = glob.IsMatch( "Assets/Textures/example.png" );

Console.WriteLine( isMatch );