I am trimming an NSString in the following way:
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"X = (\\d+.\\d+), Y = (\\d+.\\d+), (%@)" options:0 error:NULL];
NSTextCheckingResult *match = [regex firstMatchInString:txt.text options:0 range:NSMakeRange(0, [txt.text length])];
if (match) {
NSRange firstHalfRange = [match rangeAtIndex:1];
NSString *xString = [txt.text substringWithRange:firstHalfRange];
NSRange secondHalfRange = [match rangeAtIndex:2];
NSString *yString = [txt.text substringWithRange:secondHalfRange];
NSRange thirdHalfRange = [match rangeAtIndex:3];
NSString *colorString = [txt.text substringWithRange:thirdHalfRange];
NSLog(@"X = %@, Y = %@, Color: %@", yString, xString, colorString);
}
The NSString looks like this:
@"this is the content. The content of this string may vary, as well as the length, and my include any characters, with numbers X = 295.000000, Y = 207.500000, TheWhite"
The part Y = 295.000000 X = 207.500000 remains always the same, apart from the X and Y numbers which may change, as well as the: TheWhite, which may become for e.g. TheBlack
Using this method I successfully extract the X and Y values, but not the final string. What am I doing wrong?
Your pattern ends with
(%@). I should end with(.+)instead.