juman said:
> I have som strings that I want to clean up. They can contain digits,
> some special characters (white space etc) and a comma and all I want to
> keep is the digits and the comma? Any idea how I could do this?
>

>From Learning Perl Chp9:

"9.6.1. Global Replacements with /g

As you may have noticed in a previous example, s/// will make just one
replacement, even if others are possible. Of course, that's just the
default. The /g modifier tells s/// to make all possible
nonoverlapping[206] replacements:

    [206]It's nonoverlapping because each new match starts looking just
beyond the latest replacement.

$_ = "home, sweet home!";
s/home/cave/g;
print "$_\n";  # "cave, sweet cave!"

A fairly common use of a global replacement is to collapse whitespace;
that is, to turn any arbitrary whitespace into a single space:

$_ = "Input  data\t may have    extra whitespace.";
s/\s+/ /g;  # Now it says "Input data may have extra whitespace."

Once we show collapsing whitespace, everyone wants to know about stripping
leading and trailing whitespace. That's easy enough, in two steps:[207]

    [207]It could be done in one step, but this way is better.

s/^\s+//;  # Replace leading whitespace with nothing
s/\s+$//;  # Replace trailing whitespace with nothing"


Now you know what to use, just figure the regex ;-)

--
Just getting into the best language ever...
Fancy a [EMAIL PROTECTED] Just ask!!!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to