Forum: Ruby String search backwards?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Toby DiPasquale (Guest)
on 2006-01-24 22:05
Hi all,

Can Ruby search a string backwards? I can't find any reference to this
in the docs or online, but it seems as if you should be able to do this.

What I would like, ideally, is a method like:

n = rstrstr( orig_str, sub_str)

where n is the starting index of the last occurrence of sub_str in
orig_str. Anybody know how to do this? I tried using the 'r' modifier to
// but that failed as well.
Matthew M. (Guest)
on 2006-01-24 22:22
(Received via mailing list)
n = orig_str.rindex(sub_str)
This topic is locked and can not be replied to.