首页 > 解决方案 > 如何编写正则表达式来过滤 {key:value} 字符串

问题描述

我有一个这样的字符串

    NSString *content = @"{"year":2019,"month":12,"day":08}";

我怎样才能得到年,月和日的价值?

NSRegularExpression *testExpression = [NSRegularExpression regularExpressionWithPattern: @"(\w+):(\w+)" options:NSRegularExpressionCaseInsensitive error:nil];
    NSArray *matches = [testExpression matchesInString:content
                                               options:0
                                                 range:NSMakeRange(0, [content length])];

标签: objective-cregex

解决方案


推荐阅读