Reputation: 1394
I have a string which comes as Filename [1234568]. I need to delete the square bracket part of the string and just get the filename. How can we retrieve just the file name?
Upvotes: 0
Views: 106
Reputation: 423
Below Regex may help you
NSMutableString *str = [@"Filename [1234568]" mutableCopy];
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"\\[.+?\\]"
options:NSRegularExpressionCaseInsensitive
error:NULL];
NSString *newStr = [regex replaceMatchesInString:str
options:0
range:NSMakeRange(0, [str length])
withTemplate:@""];
Upvotes: 1