[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: Perl expression
> Hi all,
> Could someone tell me a regular expression to remove leading spaces in a
> string? For example in " Hello World", i want to remove all the
> spaces *before* hello.
$String = " Hello World";
$String =~ s/^\s*//;
That would do. ^ indicates from the beginning. \s stands for a single
space (this can be ' ' or a TAB). * stands for 0 or more occurrences.
So ^\s* means, from the beginning(^), 0 or more occurrences (*) of space
Similarly $ indicates end. So if u want to remove all spaces in the end,
changes the expression as:
$String =~ s/\s*$//;