Looking for a pattern

Z

Zhao Yi

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

Harald Eilertsen

Zhao said:
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!
 
Z

Zhao Yi

Harald said:
Zhao said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top