I have a problem with reading the image path of a string like -> background-image:url(/assets/test.jpg)
I wanna have the string inside of the brackets without the brackets self.
Here is my code used:
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\bbackground-image:url\(.*\)\\b" options:NSRegularExpressionCaseInsensitive error:nil];
thumbnail = [regex stringByReplacingMatchesInString:thumbnail options:0 range:NSMakeRange(0, [thumbnail length]) withTemplate:@"$1"];
what i get is (/assets/test.jpg)
Use the following pattern to get the expeced result:
Applied to your code:
Using this the result will be “/assets/test.jpg”, just as you want it to be.
Your code should have given you a warning about an unknown escape sequence for “\(“. You have to use “\\(” to escape a “(“. Also get rid of “\\b” at the beginning and end of your pattern.
But be aware that this pattern only works when your string only contains “background-image:url(somevaluehere)”
EDIT:
What does \\b mean?
\\b is a word boundary, usually expressed as \b. In an NSString you need to write \\b because you need to escape the \ so it will be treated as real backslash.
Here some information on what word boundaries match:
Taken from http://www.regular-expressions.info/wordboundaries.html
I hope this clarifies this a bit.