Looking for a pattern

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.

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!

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 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