Lee Goddard wrote:
> 
> > Lee Goddard wrote:
> > >
> > > > > I need to split a string at all full-stops '.'
> > > > > unless they are part of a sub-string within quotes.
> > > > >
> > > > > Should I manually loop over the file, setting flags,
> > > > > or can I do this with a regular expression?
> > > >
> > > > And of course, I need to have escaped single-quotes too,
> > > > \'
> > >
> > > In other words, can anyone put this into a regex?!
> > >
> > > $file = "Split now. Quoting so do not split \\'here. \\', but now. Do not 
>'fullstop.' but now. And again. Finally.";
> > >
> > > for (my $i=0; $i<length($file); $i++){
> > >         my $c = substr($file,$i,1);
> > >         if ($c eq '\\'){ $out .= $c; next }
> > >         if ($c eq "'") { $q = not $q }
> > >         if ($c eq "." and not $q) { $c .= "\n" }
> > >         $out .= $c;
> > > }
> > >
> > > warn $out;
> >
> > Assuming you really wouldn't have a ' ' after the here. since it's in quotes
> > (if it's possible, you could add a check for [^'] after the \s+):
> >
> > my $file = "Split now. Quoting so do not split 'here.', but now. Do not 
>'fullstop.' but now. And again.  Finally.";
> >
> > $file =~ s/(?:^|\G)(.*?\.)(?:\s+|\s*$)/$1\n/g;
> > print $file, "\n";
> 
> Many thanks, Bill.   I kinda hoped you'd be out there today....
> 
> ?: is news to me: off to perldoc perlre.
> 
> But, things got a lot more complex when I realised that quotes
> can also be round or square brackets, and so I'm saving programming
> time by doing a loop with flags.

You would think that if the substr is in ', ", ) or ] that there would be no space 
before the closing quote.  So it shouldn't matter.  You could remove the space 
before the quote first and then run the above RE.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.todbe.com/
  / ) /--<  o // //      Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to