Availability:built-in
Pick out a sub-atom of length 3 starting a 0-based index 2:
?- sub_atom(aaxyzbbb, 2, 3, After, SubAtom). After = 3, SubAtom = xyz.
On backtracking, matches are delivered in order left-to-right (i.e. Before increases monotonically):
?- sub_atom('xATGATGAxATGAxATGAx', Before, Length, After, 'ATGA'). Before = 1, Length = 4, After = 14 ; Before = Length, Length = 4, After = 11 ; Before = 9, Length = 4, After = 6 ; Before = 14, Length = 4, After = 1 ; false.
See also sub_string/5, the corresponding predicate for SWI-Prolog strings.