Skip to content
instance method

String#lstrip

() -> ::String
lstrip(*selectors) → new_string

Returns a copy of self with leading whitespace removed; see Whitespace in Strings:

Example
whitespace = "\x00\t\n\v\f\r "
s = whitespace + 'abc' + whitespace
# => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r "
s.lstrip
# => "abc\u0000\t\n\v\f\r "

If selectors are given, removes characters of selectors from the beginning of self:

Example
s = "---abc+++"
s.lstrip("-") # => "abc+++"

selectors must be valid character selectors (see Character Selectors), and may use any of its valid forms, including negation, ranges, and escapes:

Example
"01234abc56789".lstrip("0-9") # "abc56789"
"01234abc56789".lstrip("0-9", "^4-6") # "4abc56789"

Related: see Converting to New String.

Ruby version changes

  1. 3.0
See also #lstrip! #ljust #lines #match also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0