regextextpad

Find the last occurence of a needle in a haystack


In Textpad, is it possible to find the last occurence of a string within a string, so, for instance...

Find the last occurrence of _ within

FF_SF_FIRE_STRATEGY_G

So that you can then obtain either FF_SF_FIRE_STRATEGY or G

?

UPDATE: This solves half the problem: _[A-Z]\>


Solution

  • You may use a negative lookahead based regex:

    _(?!\S*_)
    

    RegEx Demo

    Here (?!\S*_) is a negative lookahead that asserts that we don't have any more _ following 0 or more non-whitespace characters on right hand side.