flags can be any combination of the following flags (combined with bitwise _BAR_ operator):
If limit is specified, then only substrings up to limit are returned, and if limit is -1, it actually means "no limit", which is useful for specifying the flags.