Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8251387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:13:15+00:00 2026-06-08T00:13:15+00:00

Ok I am trying to remove a very stubborn space from the beginning of

  • 0

Ok I am trying to remove a very stubborn space from the beginning of my string using regex.
This string is being parsed from a CSV file into Perl using the Text:CSV module and when I print a Dumper of the string I get:

$VAR1 = ' Mgmt-General-Other';  

now I have tried to use Regex to remove this space, someone will tell me to use:

$string =~ s/\s+$//;

I have already tried this as well as:

$string =~ s/\s//g;

and

$string =~ s/^\s//g;

and none of these worked, the middle one pulled every space out of everything except for the one I wanted. I’m trying to loop through a 2,000 line CSV file so I’d rather make this automated and not have to make a special case for this one weird instance.

Is there any way that this character at the beginning is not a space or a white space? Or how can I take it out?

Adding more things that I have tried;

$string =~ s/^\s+//;

here is my code:

my @value = @columns[1..12];
my $string = @value[9];
$string =~ s/^\s+//;
$string =~ s/\s+$//;
print Dumper $string;

if it matters these are my declarations at the top of the script:

use strict;
use DBI;
use Getopt::Long;
use Spreadsheet::WriteExcel;
use Spreadsheet::WriteExcel::Utility;
use Data::Dumper;
use Text::CSV;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:13:17+00:00Added an answer on June 8, 2026 at 12:13 am

    You were pretty close actually, as the correct regex for replacing whitespace at the beginning of the string would be:

    $sting =~ s/^\s+//;
    

    As for other solutions:

    $sting =~ s/\s+$//; # the same as 'rtrim', removes whitespace at the end of the string
    $sting =~ s/\s//g;  # will just remove all whitespace
    $sting =~ s/^\s//g; # will remove single whitespace symbol right at the beginning of the string.
    

    UPDATE: turned out you had a \xA0 (so-called ‘non-breakable whitespace’, which is NOT included in \s) in your string. ) Try this:

    $sting =~ s/^[\s\xA0]+//;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this regular expression to remove white space and line breaks from
I am trying to remove the very last character from a TextCtrl object in
I'm trying to remove wiki formatting from some text so it can be parsed.
I am trying to remove the LAST double-quote from every line of a file.
In trying to remove black border from spin button onclick (btw, I'm very interesting
I am trying to remove short strings from a vector. std::vector<std::string> vec; // ...
I am trying to write a very simple method to remove duplicates in a
I'm trying to remove part of the path in a string. I have the
I'm trying to remove scrollbar from my facebook app. I tried js solution, that
I'm trying to remove a specific graph object from the zedgraph, is it possible....?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.