Re: Howto Delete 3 Leftmost Characters

You can delete white spaces at the start and at the end of a string like

string=" a long string "
string1=string.sub(/^ +/,’’)
string2=string.sub(/ +$/,’’)

The ^ stands for eliminating things at the start, the + stands for
1 or more occurrences of a whitespace, and the $ stands for looking to
end of a string.

I can’t comment on whether it’s the best way to learn about Regexp, but
has a special Ruby section.

If you want to know it all, there is a book Mastering Regular
by Jeffrey Friedl, published with O’Reilly … but maybe that’s too
for a start.

Best regards,


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