コガネブログ

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

【C#】文字列の末尾の数値を抽出する正規表現

概要

using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;

public static class Example
{
    [MenuItem( "Tools/Hoge" )]
    private static void Hoge()
    {
        var input   = "Item001";
        var pattern = "([0-9]*$)";
        var regex   = Regex.Match( input, pattern );

        Debug.Log( regex.Success );
        Debug.Log( regex.Groups[ 1 ] );
    }
}