sugarkannan has asked for the wisdom of the Perl Monks concerning the following question:

How to ignore/replace all whitespaces,tab spaces, new line from a given string in REGEX??
How to do it in a following string ??
$name=" product ";
  • Comment on How to ignore/replace all whitespaces,tab spaces, new line from a given string in REGEX ??
  • Download Code

Replies are listed 'Best First'.
Re: How to ignore/replace all whitespaces,tab spaces, new line from a given string in REGEX ??
by ikegami (Patriarch) on Nov 21, 2005 at 14:36 UTC
    By "ignore", do you mean "remove"?
    $name =~ s/\s+//g;
      Thanx a lot !! It worked for me !!

      -Sugar
        Keep in mind that will remove the spaces between words too. If you just want to remove the leading and trailing spaces, use:
        $name =~ s/^\s+//; $name =~ s/\s+$//;
Re: How to ignore/replace all whitespaces,tab spaces, new line from a given string in REGEX ??
by davorg (Chancellor) on Nov 21, 2005 at 14:40 UTC

    Not sure what you mean by "ignore" all white space, and you don't say what you want to "replace" it with, so this code just removes all white space.

    $name =~ s/\s//g;
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg