From: Young Moon Date: 2007-12-29T21:30:01+09:00 Subject: Re: trimming leading zeros On Dec 29, 5:00 pm, Dipesh Batheja wrote: > Is there any function in ruby which allows you to trim leading zeros (or > any specific character) from a string. Or if there is some reg > expression that i can use? > -- > Posted viahttp://www.ruby-forum.com/. Hi, for simple character replacement, you may do something like "####helloworld".gsub!(/^#+/,'') the same can be written in String class if you use this too often, class String def trim_lead(n) self.gsub!(/^#{n}+/,'') end end puts "00001234".trim_lead("0") but when you use this to replace any special characters used internally by regex (for e.g., $) you have to do something like "$$$1234".trim_lead("\\$") Others may suggest better ways.