You can use this pattern as well:
[^&]&[^&]
and a call to some language specific SPLIT
function should do the job.
If this is for iOS platform, try this example in a separate app:
NSString *string = @"STRING1 && STRING2 & STRING3 AND STRING4"; //[NSString stringWithFormat:@"%@", @""];
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^&]&[^&]"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSUInteger numberOfMatches = [regex numberOfMatchesInString:string
options:0
range:NSMakeRange(0, [string length])];
NSLog(@"numberOfMatches : %d", numberOfMatches);
NSArray *matches = [regex matchesInString:string
options:0
range:NSMakeRange(0, [string length])];
for (NSTextCheckingResult *match in matches) // adjust loop per your criteria
{
NSRange matchRange = [match range];
// Pick the separator
NSLog(@"::::%@", [string substringWithRange:matchRange]);
// Splitted string array
NSArray *arr = [string componentsSeparatedByString:[string substringWithRange:matchRange]];
NSLog(@"Splitted String : %@", arr);
}