This expression takes a four-part string separated with three colons, for example
quick:brown:fox:jumps
The only requirement to that string is that three colons must be there, that the items between the colons (or between the colon and the beginning/the end of the string) had at least one non-colon character, and that the content occupied the entire string.
The expression creates four capturing groups - one for each of the colon-separated elements of the string.
Since the non-colon character class [^:]+?
is always followed by a colon, the reluctant quantifier can be removed:
^([^:]+):([^:]+):([^:]+):(.*)$
A way to accomplish the same thing without a regex would be using componentsSeparatedByString:
, and checking that you get exactly four components back:
NSArray *parts = [str componentsSeparatedByString:@":"];
if (parts.length == 4) {
... // We've got a good string
}