He said he wanted to replace all nonalphanumerics, and I was assuming that
meant white space as well, regardless of where in the string it is located.

Scot



-----Original Message-----
From: Janek Schleicher [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 04, 2002 8:51 AM
To: [EMAIL PROTECTED]
Subject: RE: Replacing with Regular expressions


Scot Robnett wrote at Tue, 04 Jun 2002 05:13:13 +0200:

>>      $foo =~ s/\W*/_/g;
>>
>>      http://www.oreilly.com/catalog/regex/
> ...
>
> I want to allow only the a-z, A-Z, and 0-9 characters and I want to
replace all others with _ when
> writing the file to the server.
>
> Can you tell me what would be this regular expression?
>

The regexp should be $foo =~ s/\W/_/g;

\W* matches every zero length, so e.g.

$a = 'x := y';
$a =~ s/\W*/_/g;
print $a;

prints _x__y_;

(first matches 0-length before 'x',
 then ' := ' after x,
 then 0-length between ' := ' and 'y',
 then 0-length after 'y'
)

Instead my solution would print x____y

Greetings,
Janek

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.368 / Virus Database: 204 - Release Date: 5/29/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.368 / Virus Database: 204 - Release Date: 5/29/2002


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to