当前位置:编程学习 > C#/ASP.NET >>

请求用正则匹配一个值。

--------------------编程问答--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = @"&&&{""passToken"":""Aq3FBlXT880Y+FyC7LB8rWGVyfCWqMkOkh6Wkpuxc0tfKkt70RoSL5FrTQMmaHJ0KMU1c0HJp2gsBCTSKiHtwWdDgb5gmg0K89BaIVqHD9rrwAyFM9zywIaobeiAgHK1lGhOwHg5Kw4hsyqsVxJOYvfdPikYiNQydlxWbLLjeZ+ISV275VHSMVl7HsxdGRZw+m+Ct64AB4/ouvF9gL5I2A=="",""ssecurity"":""pC6XeSO6ddZhDA9xxEVkug=="",""desc"":""成功"",""nonce"":920376860430596096,""location"":""https://account.xiaomi.com/sts?sid=passport&followup=%2Fpass%2FuserInfo%3FuserId%123456&sign=aLszqIkW597fzJ2WNrIcVGvLwWg%3D&auth=a7U64V4RyzUBie7POKXIm2OTj1evZqe1Ac0xPQYfvnYZ2FU%2F3crjzJkgEk3PinmxWSeOu%2BfiRVC%2FNadJtT9ZexuC32cfuktLUTxdwp0H2tckv92pkz%2B4LhntR2f6nDHP3oNO2%2BFFvfDBew5%2FB4mWX6k8jthUCyYs4pDs8qkCoZY%3D&nonce=8hWxcxbIVRkBYOrG&_ssign=RXPm%2F9Yrl9VwCMLXfFFcLVUj2ZQ%3D"",""userId"":12345678,""captchaUrl"":null,""psecurity"":""ffEwpBsdBQvS684YJPvQCw=="",""code"":0}";
            string result = Regex.Match(s, @"\""location\"":\""([^\""]+)\""").Groups[1].Value;
            Console.WriteLine(result);
        }
    }
}
--------------------编程问答-------------------- (?<=location":")(.|\n)*(?=\&nonce)
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,