|
Posted by jh3an on March 11, 2008, 12:41 am
Please log in for more thread options
Thank you everyone !
|
|
Posted by Jim Gibson on March 11, 2008, 1:53 pm
Please log in for more thread options
In article
> I would propose the following for your case :
> @num = split /D+/,$x;
You left out one backslash:
split /\D+/,$x;
> This will split with any a-zA-Z
Actually, \D stands for [^0-9], which is much larger than [a-zA-z] and
includes a lot of punctuation characters.
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
|
|
Posted by Abigail on March 11, 2008, 5:46 pm
Please log in for more thread options _
Jim Gibson (jimsgibson@gmail.com) wrote on VCCCVI September MCMXCIII in
~~ In article
~~
~~ > I would propose the following for your case :
~~ > @num = split /D+/,$x;
~~
~~ You left out one backslash:
~~
~~ split /\D+/,$x;
~~
~~ > This will split with any a-zA-Z
~~
~~ Actually, \D stands for [^0-9], which is much larger than [a-zA-z] and
~~ includes a lot of punctuation characters.
Well, it's not that simple.
If *both* the pattern *and* the subject (the string matched against)
are not in UTF-8, then, and only then, does \D equal [^0-9].
However, if either of them is in UTF-8 format (which does not necessarely
mean they contain a non-ASCII character), then \D excludes a lot more
than just the digits 0 to 9.
$ perl -wE 'chr =~ /[^0-9]/ or $c ++ for 0x00 .. 0xD7FF; say $c'
10
$ perl -wE 'chr =~ /\D/ or $c ++ for 0x00 .. 0xD7FF; say $c'
220
In fact, using \d (\D) as a shortcut for [0-9] ([^0-9]) is often just
plain wrong.
Abigail
--
# Perl 5.6.0 broke this.
%0=mapABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$01$2$0$0$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
|
|
Posted by Abigail on March 16, 2008, 6:03 am
Please log in for more thread options _
Ben Bullock (benkasminbullock@gmail.com) wrote on VCCCXI September
[] On Tue, 11 Mar 2008 21:46:38 +0000, Abigail wrote:
[]
[] > If *both* the pattern *and* the subject (the string matched against) are
[] > not in UTF-8, then, and only then, does \D equal [^0-9].
[] >
[] > However, if either of them is in UTF-8 format (which does not
[] > necessarely mean they contain a non-ASCII character), then \D excludes a
[] > lot more than just the digits 0 to 9.
[] >
[] > $ perl -wE 'chr =~ /[^0-9]/ or $c ++ for 0x00 .. 0xD7FF; say $c' 10
[] > $ perl -wE 'chr =~ /\D/ or $c ++ for 0x00 .. 0xD7FF; say $c' 220
[]
[] You need to use (0x00 .. 0xD7FF, 0xE000 .. 0xFDCF, 0xFDF0.. 0xFFFD) here,
Nah, all I needed to show was that there were more than 10. ;-)
Abigail
--
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT
|
| Similar Threads | Posted | | FAQ 6.4: I put a regular expression into $/ but it didn't work. What's wrong? | October 27, 2004, 5:03 pm |
| FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong? | March 2, 2005, 12:03 am |
| FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong? | April 27, 2005, 11:03 pm |
| FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong? | July 13, 2005, 4:03 am |
| FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong? | September 14, 2005, 10:03 pm |
| FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong? | November 5, 2005, 5:03 pm |
| FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong? | November 24, 2005, 11:03 pm |
| FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong? | December 28, 2005, 11:03 am |
| FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong? | May 6, 2006, 9:03 am |
| FAQ 6.4 I put a regular expression into $/ but it didn't work. What's wrong? | August 24, 2006, 3:03 am |
|