Forum: Ruby Looking for a pattern

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.
7fbd0e99b27064b14793f028022974e5?d=identicon&s=25 Zhao Yi (youhaodeyi)
on 2008-12-04 08:30
I am looking for a pattern to match the last underline and its following
string with "####". for example,

"abc_def_ghi"  => "abc_def####"

If I use _.* as the pattern it will replace begin with the first
underline. Which pattern is suite for this case?

thanks.
D893eb5f378dd57752aaf5bf4a753bb0?d=identicon&s=25 Harald Eilertsen (Guest)
on 2008-12-04 08:56
(Received via mailing list)
Zhao Yi wrote:

> I am looking for a pattern to match the last underline and its following
> string with "####". for example,
>
> "abc_def_ghi"  => "abc_def####"

"abc_def_ghi".match(/_[^_]*$/)

That should do the trick, shouldn't it?

H!
7fbd0e99b27064b14793f028022974e5?d=identicon&s=25 Zhao Yi (youhaodeyi)
on 2008-12-04 08:59
Harald Eilertsen wrote:
> Zhao Yi wrote:
>
>> I am looking for a pattern to match the last underline and its following
>> string with "####". for example,
>>
>> "abc_def_ghi"  => "abc_def####"
>
> "abc_def_ghi".match(/_[^_]*$/)
>
> That should do the trick, shouldn't it?
>
> H!

Yes, very good. thanks.
This topic is locked and can not be replied to.