Thanks for the reply MadSpy, :)
Yeah, the afterLast() and beforeLast() functions are kind of a shorthand for stuff that can certainly be done with more functions.
One of my main reasons for incorporating them into my plugin, is to make certain expressions a bit easier to understand at a glance.
The afterLast() function especially is pretty straightforward to recreate with built-in text expressions.
I may not have explained the beforeLast() that clearly, but it returns everything before the last slicer string found, rather than just the previous token.
So I think
beforeLast( src , separator )
is not quite the same as
tokenat( src , tokencount( src , separator ) - 2 , separator )
for instance, given
var src = "root/trunk/branch.jpg"
var separator = "/"
beforeLast( src , separator ) // returns "root/trunk"
tokenat( src , tokencount( src , separator ) - 2 , separator ) // returns "trunk"
This is actually the same issue I ran into when trying to create that functionality with the built-in text expressions, and the reason I thought it might be handy to have a beforeLast() in particular. Otherwise you have to either get the index of the last token, (which can be tricky with "find()" if there's another identical token elsewhere), and crop from the start of the src string to it's index; or you have to recombine all but the last token, reinserting the separators back in-between the remaining tokens. Both of those are doable, but they start getting a bit convoluted looking compared to the beforeLast() expression.