Re: Regexp non-alphanumerics to spaces
- From: rvtol+news@xxxxxxxxxxxx (Dr.Ruud)
- Date: Sat, 31 Mar 2007 10:18:38 +0200
"John W. Krahn" schreef:
Dr.Ruud:
John W. Krahn:
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. :-)
Not really, the \s did no harm, it was just extra.
The space I am always concerned about is 0xA0:
$ perl -wle '$_ = "\xA0"; /\s/ and print "s"'
$ perl -wle '$_ = "\xA0\x{100}"; chop; /\s/ and print "s"'
s
This is because in Perl (5.8?) the first string is a Latin1 string, and
the second a utf8 string.
--
Affijn, Ruud
"Gewoon is een tijger."
.
- References:
- Regexp non-alphanumerics to spaces
- From: Grant
- Re: Regexp non-alphanumerics to spaces
- From: Rob Dixon
- Re: Regexp non-alphanumerics to spaces
- From: John W. Krahn
- Re: Regexp non-alphanumerics to spaces
- From: Dr.Ruud
- Re: Regexp non-alphanumerics to spaces
- From: John W. Krahn
- Regexp non-alphanumerics to spaces
- Prev by Date: Ruby
- Next by Date: Re: create gui
- Previous by thread: Re: Regexp non-alphanumerics to spaces
- Next by thread: Re: Fundamental pipe questions
- Index(es):
Relevant Pages
|