Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Regular Expression and trimming

by akm2 (Scribe)
on Mar 08, 2001 at 20:52 UTC ( [id://63002]=perlquestion: print w/replies, xml ) Need Help??

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

The expression is intented to trim the spaces off the front and back of a string. Example: "          Andrew Mitchell" would be trimmed to "Andrew Mitchell"

Thats not happening. Here is the code, Any advise?

               ($BKCUM_CNUM[$i]) = substr ($line, 0, 7) =~ m/^\s*(.*)\s*$/;

Replies are listed 'Best First'.
Re: Regular Expression and trimming
by Tuna (Friar) on Mar 08, 2001 at 20:59 UTC
    Right from the Cookbook:
    $string =~ s/^\s+//; $string =~ s/\s+$//;
Re: Regular Expression and trimming
by danger (Priest) on Mar 08, 2001 at 21:04 UTC

    Yes, I suggest you visit the FAQ more often -- your question, and its answer, is contained therein.

Re: Regular Expression and trimming
by arhuman (Vicar) on Mar 08, 2001 at 21:01 UTC

    $string =~ s/^\s*(.*?)\s*$/\1/;

    "Trying to be a SMART lamer" (thanx to Merlyn ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://63002]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found