Objective-C的如何写从字符的正则表达式,直到第一匹配*

问题描述 投票:-1回答:1
\r\nThis PM was sent by [ helloworld ] [email protected],\r\nMembership Status : Non-Verified Member\r\nhttp://www.gg.com/A/F/U.asp?UserID=helloworld@1\r\n\r\n\r\n\r\n\r\n\r\nHi, may i know does the item still available?\r\n\r\n\r\n\r\n  *** This email was sent using www.gg.com***

NSString *regexStr = @"@1(.*?)[\\*]";
NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:&error];
NSArray *matches = [regex matchesInString:message options:NSMatchingReportCompletion range:NSMakeRange(0, [message length])];

if ([matches count] > 0) {
    for (NSTextCheckingResult *match in matches) {
        NSString* matchText = [message substringWithRange:[match range]];
        NSLog(@"match: %@", matchText);
        NSRange group1 = [match rangeAtIndex:1];
        NSLog(@"group1: %@", [message substringWithRange:group1]);
    }
}

我希望得到“你好,我可以知道确实仍然可用的项目?”从字符串上述目标C

ios objective-c regex
1个回答
0
投票

这应该工作。

NSString *regexStr = @"@1(.*?)\\*";

还使用NSRegularExpressionDotMatchesLineSeparators选项。

© www.soinside.com 2019 - 2024. All rights reserved.