String search backwards?

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.

n = orig_str.rindex(sub_str)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs