There's enough duplication below to make me want to write this as <code>
if (((fl && strcmp(fl, "first") == 0) ? SelectNextItemMatching : SelectLastItemMatching)(ctx, regex, begin_ptr, end_ptr, match, prev))
{ ret = true; }
</code> but I guess some would find that confusing !