in reply to Substitute _last_ occurence in string?

Hello,

$string =~ s/two (.*?)$/$1/ should work, though after a little testing, I find that it does not. I don't know why. Anyone?

Scott

Update: I must admit, I like the trickyness of using the reverse.

Replies are listed 'Best First'.
Re: Re: Substitute _last_ occurence in string?
by Hofmator (Curate) on Jul 25, 2001 at 18:46 UTC

    Regexes always give you the leftmost longest match. To do something like you want you best use the greediness of .* $string =~ s/(.*) two/$1/;

    Update: I have simplified the unnecessarily complicated regex.

    -- Hofmator