Re: Regexp non-alphanumerics to spaces
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Fri, 30 Mar 2007 13:37:00 -0700
Rob Dixon wrote:
Grant wrote:
Hello, can you guys show me how to convert each non-alphanumeric
character in a string to a space, and then convert any number of
consecutive spaces in the string to a single space?
If I need to specify exactly which characters I want converted to
spaces, I'd be happy with just the "." character.
Hi Grant.
$text =~ s/[^[:alnum:]]/ /g;
$text =~ s/\s+/ /g;
will do what you want.
Or with one regexp:
$text =~ s/[[:^alnum:]\s]+/ /g;
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- Follow-Ups:
- Re: Regexp non-alphanumerics to spaces
- From: Dr.Ruud
- Re: Regexp non-alphanumerics to spaces
- References:
- Regexp non-alphanumerics to spaces
- From: Grant
- Re: Regexp non-alphanumerics to spaces
- From: Rob Dixon
- Regexp non-alphanumerics to spaces
- Prev by Date: Re: www::mechanize question
- Next by Date: Re: Exiting loops
- Previous by thread: Re: Regexp non-alphanumerics to spaces
- Next by thread: Re: Regexp non-alphanumerics to spaces
- Index(es):
Relevant Pages
|
|