先読み(?=
)がここに間違っている、あなたは正しく\d
(それは\\d
になります)、最後に脱出していないではなく、少なくとも、あなたは取り残さ数量*
(0回以上)と+
(1回以上):
NSString *aTestString = @"[email protected]#[email protected]#[email protected]#$**888***";
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"value=[^\\d]*(\\d+)"
options:0
error:NULL
];
[regex
enumerateMatchesInString:aTestString
options:0
range:NSMakeRange(0, [aTestString length])
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
NSLog(@"Value: %@", [aTestString substringWithRange:[result rangeAtIndex:1]]);
}
];
編集:はここで、より洗練された模様です。それは=
の前に単語をキャッチし、その後、非数字を破棄し、後で数字をキャッチします。
NSString *aTestString = @"[email protected]#[email protected]#[email protected]#$**888***";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(\\w+)=[^\\d]*(\\d+)" options:0 error:NULL];
[regex
enumerateMatchesInString:aTestString
options:0
range:NSMakeRange(0, [aTestString length])
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
NSLog(
@"Found: %@=%@",
[aTestString substringWithRange:[result rangeAtIndex:1]],
[aTestString substringWithRange:[result rangeAtIndex:2]]
);
}
];
// Output:
// Found: foo=777
// Found: bar=888
あなたは正しいですね。私はちょうどあなたの最初のヘルプに基づいてあなたの編集を考え出し、コメントしようとしていた:) 1つのことtho、私は(値=)[^ \\ d] *(\\ d +) = "は常に保証されます。あなたの答えに感謝します。正しいとフラグを立てる。 –