Re: Regexp non-alphanumerics to spaces



Dr.Ruud wrote:
"John W. Krahn" schreef:
Rob Dixon:
Grant:

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?
$text =~ s/[^[:alnum:]]/ /g;
$text =~ s/\s+/ /g;
$text =~ s/[[:^alnum:]\s]+/ /g;

Isn't \s already part of [[:^alnum:]]?

Oops, yes, I was wrong. :-)


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
.



Relevant Pages

  • Re: Regexp non-alphanumerics to spaces
    ... consecutive spaces in the string to a single space? ... "Gewoon is een tijger." ...
    (perl.beginners)
  • Re: Regexp non-alphanumerics to spaces
    ... consecutive spaces in the string to a single space? ... Oops, yes, I was wrong. ...
    (perl.beginners)
  • Re: Counting a Character
    ... consecutive spaces to a single space. ... its position in the original string. ... (no additional characters), you can add a dummy character to the string and do ...
    (microsoft.public.excel.misc)
  • Re: Regexp non-alphanumerics to spaces
    ... character in a string to a space, and then convert any number of ... consecutive spaces in the string to a single space? ...
    (perl.beginners)
  • Re: A repost - Permuting SPACES within a String of words
    ... Then you should check for empty cells array ... Use ubound to find out how many cells your array contains ... > a) where there is no space between any of the words in the string ... > together and the lone word is separated by a single space. ...
    (microsoft.public.excel.programming)