rgb(34, 34, 34) to UIColor
ios, regex, uicolor
Solution
UIColor uses a 0-1 instead of 0-255 system so you just need to convert it like so:
[UIColor colorWithRed:34.0/255.0 green:34.0/255.0 blue:34.0/255.0 alpha:1.0];
Update
After re-reading your question I realized your real problem isn't converting to UIColor but getting the values. I don't know much about regex but NSScanner is a simple Objective-C object that can do the same thing, albeit more verbose. Try this on for size. I'm sure there could be better ways even maybe more efficient uses of the NSScanner itself but this definitely works and will work for any int values that come through.
NSString *backgroundColorString = @"rgb(34, 34, 34)";
NSScanner *scanner = [NSScanner scannerWithString:backgroundColorString];
NSString *junk, *red, *green, *blue;
[scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:&junk];
[scanner scanUpToCharactersFromSet:[NSCharacterSet punctuationCharacterSet] intoString:&red];
[scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:&junk];
[scanner scanUpToCharactersFromSet:[NSCharacterSet punctuationCharacterSet] intoString:&green];
[scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:&junk];
[scanner scanUpToCharactersFromSet:[NSCharacterSet punctuationCharacterSet] intoString:&blue];
UIColor *backgroundColor = [UIColor colorWithRed:red.intValue/255.0 green:green.intValue/255.0 blue:blue.intValue/255.0 alpha:1.0];
Problem
I have a RGB string in the form `rgb(34, 34, 34)`. I want to parse it to a `UIColor` using iOS. I believe I need a regex for this, but I can't seem to crack it. This is what I have so far. ``` NSString *regExString = @"(.*?)rgb\((\d+), (\d+), (\d+)\)"; NSError *error = nil; NSRegularExpression *regEx = [NSRegularExpression regularExpressionWithPattern:regExString options:NSRegularExpressionCaseInsensitive error:&error]; NSArray *matches = [regEx matchesInString:backgroundColorString options:NSRegularExpressionCaseInsensitive range:NSMakeRange(0, backgroundColorString.length)]; ``` If anybody could send me in the right direction, that would be great.