# Re: Howto Delete 3 Leftmost Characters

**URL:** <https://www.ruby-forum.com/t/re-howto-delete-3-leftmost-characters/100625>\
**Category:** Ruby\
**Created:** [July 31, 2006, 12:36am UTC](https://www.ruby-forum.com/t/re-howto-delete-3-leftmost-characters/100625 "2006-07-31T00:36:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 31, 2006, 12:36am UTC](https://www.ruby-forum.com/t/re-howto-delete-3-leftmost-characters/100625/1 "2006-07-31T00:36:03Z")

</div>

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

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

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

I can’t comment on whether it’s the best way to learn about Regexp, but  
_[http://www.regular-expressions.info](http://www.regular-expressions.info)_  
([http://www.regular-expressions.info](http://www.regular-expressions.info))  
has a special Ruby section.

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

Best regards,

Axel
