C#系列 - 正则表达式

.*无法匹配中间字段

第三个参数指定为RegexOptions.Singleline即可

using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace RegTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = "spawn ./helium-wallet --format json create basic --output ./wallets/asdasd.key\r\n\rPassword: \r\n\rConfirm password: \r\n\u001b[2A\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[2APassword: [hidden]\r\n{\r\n  \"address\": \"13SmwafAbtZ4ktmdSAAGTADsTFAMAToZj1K27GcAyMzxpo2X47w\",\r\n  \"pwhash\": \"Argon2id13\",\r\n  \"sharded\": false,\r\n  \"verify\": true\r\n}\r\n";

            var pattar = @"{.*}";

            var re = Regex.Match(s, pattar,RegexOptions.Singleline);
            
            
            
            Console.WriteLine(re.Groups.Values.First());
        }
    }
}
posted @ 2021-11-08 21:54  Z_DK  阅读(32)  评论(0编辑  收藏  举报