<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><DIV>No, as the matching deleimters are captured. I can use the numbers as seperator.</DIV>
<DIV> </DIV>
<DIV><FONT face="Courier New, courier, monaco, monospace, sans-serif">perl -MData::Dumper -MRegexp::Common -le '<BR> $a="15678.91 ml; .121 0.12312 12313. r45.12 ";<BR> @a= grep {! /^$/} split /($RE{num}{real})/, $a;<BR> print Dumper \@a'<BR>$VAR1 = [<BR> '15678.91',<BR> ' ml; ',<BR> '.121',<BR> ' ',<BR> '0.12312',<BR> ' ',<BR> '12313.',<BR> ' r',<BR>
'45.12',<BR> ' '<BR> ];<BR></FONT><BR></DIV>
<DIV style="FONT-FAMILY: arial, helvetica, sans-serif; FONT-SIZE: 10pt"><BR>
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><FONT size=2 face=Tahoma>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> tiger peng <tigerpeng2001@yahoo.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Chicago.pm chatter <chicago-talk@pm.org><BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Thu, October 22, 2009 2:37:16 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [Chicago-talk] split function and zero-width seperator<BR></FONT><BR>
<DIV style="FONT-FAMILY: arial, helvetica, sans-serif; FONT-SIZE: 10pt">
<DIV>I found the answer by checking perldoc of split, it says:</DIV>
<DIV> </DIV>
<DIV>If the PATTERN contains parentheses, additional list elements are created from each matching substring in the delimiter. </DIV>
<DIV><BR>It seems I have to simplify the seperater (PATTERN) first.</DIV>
<DIV> </DIV>
<DIV><FONT face="Courier New, courier, monaco, monospace, sans-serif">perl -MData::Dumper -le '$s=chr(127);<BR> $a = "15678.91 ml; r45.12 ";<BR> $a =~ s/((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(?<!(\d|\.)))/$s/g;<BR> @a = split /$s/, $a;</FONT></DIV>
<DIV><FONT face="Courier New, courier, monaco, monospace, sans-serif"> print Dumper(@a)'<BR>$VAR1 = '';<BR>$VAR2 = '15678.91';<BR>$VAR3 = ' ml; r';<BR>$VAR4 = '45.12';<BR>$VAR5 = ' ';</FONT><BR></DIV>
<DIV style="FONT-FAMILY: arial, helvetica, sans-serif; FONT-SIZE: 10pt">
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><FONT size=2 face=Tahoma>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> tiger peng <tigerpeng2001@yahoo.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> <A href="http://chicago.pm/" target=_blank>Chicago.pm</A> chatter <chicago-talk@pm.org><BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Thu, October 22, 2009 2:11:29 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> [Chicago-talk] split function and zero-width seperator<BR></FONT><BR>
<DIV style="FONT-FAMILY: arial, helvetica, sans-serif; FONT-SIZE: 10pt">
<DIV><FONT face="arial, helvetica, sans-serif">Hello everyone,</FONT></DIV>
<DIV style="FONT-FAMILY: arial, helvetica, sans-serif; FONT-SIZE: 10pt">
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt">
<DIV style="FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif; FONT-SIZE: 10pt">
<DIV><FONT face="arial, helvetica, sans-serif"></FONT> </DIV>
<DIV><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"><FONT face="arial, helvetica, sans-serif">I am trying to isolate numbers from string, manipulate the numbers then put them back to original positions in the string. When I try to use zero-width separator, the split function looks weird, it generated much more elements than I expect.</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"><FONT face="arial, helvetica, sans-serif"></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"><FONT face="arial, helvetica, sans-serif">Are there any mistakes? Why the split behaviors like this? (The regexp looks right when I use it with s///)</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"><FONT face=Arial></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"><FONT face=Arial>Could anyone help?</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"><FONT face=Arial></FONT></SPAN> </DIV>
<DIV><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"><FONT face=Arial>Thanks,</FONT></SPAN></DIV>
<DIV><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: black; FONT-SIZE: 10pt"><FONT face=Arial>Tiger</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV>#build the seperator</DIV>
<DIV>:-) perl -le '$a = "15678.91 ml; r45.12 ";</DIV>
<DIV> $a =~ s/((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(?<!(\d|\.)))/|/g;</DIV>
<DIV> print $a'<BR>|15678.91| ml; r|45.12|</DIV>
<DIV> </DIV>
<DIV>#use the seperator in split</DIV>
<DIV>:-) perl -MData::Dumper -le '$a = "15678.91 ml; r45.12 ";</DIV>
<DIV> @a = split /((?!(\d|\.))(?<=(\d|\.)))|((?=(\d|\.))(?<!(\d|\.)))/, $a;</DIV>
<DIV> print Dumper(@a)'<BR>$VAR1 = '15678.91';<BR>$VAR2 = '';<BR>$VAR3 = undef;<BR>$VAR4 = '1';<BR>$VAR5 = undef;<BR>$VAR6 = undef;<BR>$VAR7 = undef;<BR>$VAR8 = ' ml; r';<BR>$VAR9 = undef;<BR>$VAR10 = undef;<BR>$VAR11 = undef;<BR>$VAR12 = '';<BR>$VAR13 = '4';<BR>$VAR14 = undef;<BR>$VAR15 = '45.12';<BR>$VAR16 = '';<BR>$VAR17 = undef;<BR>$VAR18 = '2';<BR>$VAR19 = undef;<BR>$VAR20 = undef;<BR>$VAR21 = undef;<BR>$VAR22 = ' ';<BR></DIV></DIV></DIV></DIV></DIV></DIV></DIV></DIV></DIV></DIV><!-- cg1.c902.mail.ac4.yahoo.com compressed/chunked Thu Oct 22 19:40:06 PDT 2009 --></div></body></html>