develooper Front page | perl.beginners | Postings from January 2002

RE: Pattern Matching - Remove Alpha

Thread Previous | Thread Next
Aaron Shurts
January 16, 2002 16:39
RE: Pattern Matching - Remove Alpha
Message ID:
Try this my man...

my @nums = split(/[a-zA-Z]+/,$stat);

Hope this helps.


-----Original Message-----
From: Hewlett Pickens []
Sent: Wednesday, January 16, 2002 3:39 PM
Subject: Pattern Matching - Remove Alpha

I am unable to use "split" with pattern matching to remove alpha
from a string and will appreciate a pointer on what I'm doing wrong.
looked in "Learning Perl" and "Programming Perl" but can't spot my

The detail:

 "$stat" is a string that has alpha and numeric data in it.
 I want to remove all of the alpha and put the numeric data into an

 The first attempt:

   my @nums = split(/a-zA-Z/,$stat); # removes all data from the string

 The second attempt:

   my @nums = split(/a-z/,$stat); # removes all data from the string

From reading, my understanding of "split":  Discards all data that
the pattern and returns a set of list values for the unmatched data.
understanding" may be the problem)

This pattern works - removes all blanks (white space) but leaves alpha
numbers which of course isn't what I want

   my @nums = split(/ +/,$stat);   # removes all blanks 


To unsubscribe, e-mail:
For additional commands, e-mail:

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About