Splitting But NOT Splitting 
Author Message
 Splitting But NOT Splitting

Can anyone give me a regular expression to perform a split where the
expression is split on a character unless the character is preceded by a
backslash (\) ?


Wed, 18 Jun 1902 08:00:00 GMT  
 Splitting But NOT Splitting


Quote:
> Can anyone give me a regular expression to perform a split where the
> expression is split on a character unless the character is preceded by a
> backslash (\) ?

#!/usr/bin/perl -w
use strict;

$_ = 'this,is separated,on \, (comma),etc.';



__END__

perldoc perlre
look for 'negative look-behind'

--
Good luck,
Abe



Wed, 18 Jun 1902 08:00:00 GMT  
 Splitting But NOT Splitting

Quote:

>Can anyone give me a regular expression to perform a split where the
>expression is split on a character unless the character is preceded by a
>backslash (\) ?

My first thought of a solution was in the same realm as Abe Timmerman's
reply.

My second though was: Wait! What will happen if you have double
backslashes? Will the backslash be escaped? So a backslash followed by a
backslash will NOT escape a comma?

In that case, this reverse approach might appeal to you.

        $_ = "This,is\\,not,is\\\\,too,separated,,!";
        print "$_\n";

        $" = '|';

--
        Bart.



Wed, 18 Jun 1902 08:00:00 GMT  
 Splitting But NOT Splitting
Hmmmm...
I tested this code ( Sun - Solaris - perl5 ) and got:

Sequence (?<...) not recognized at tst.pl line 6



Quote:


> > Can anyone give me a regular expression to perform a split where the
> > expression is split on a character unless the character is preceded
by a
> > backslash (\) ?

> #!/usr/bin/perl -w
> use strict;

> $_ = 'this,is separated,on \, (comma),etc.';



> __END__

> perldoc perlre
> look for 'negative look-behind'

> --
> Good luck,
> Abe

Sent via Deja.com http://www.deja.com/
Before you buy.


Wed, 18 Jun 1902 08:00:00 GMT  
 Splitting But NOT Splitting
++ Can anyone give me a regular expression to perform a split where the
++ expression is split on a character unless the character is preceded by a
++ backslash (\) ?

    split /(?<!\\)/ => $string;

Abigail



Wed, 18 Jun 1902 08:00:00 GMT  
 Splitting But NOT Splitting
On Tue, 06 Jun 2000 18:23:13 GMT,
++ Hmmmm...
++ I tested this code ( Sun - Solaris - perl5 ) and got:
++
++ Sequence (?<...) not recognized at tst.pl line 6

Upgrade.

Abigail



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. How to use split function to split on a backslash

2. split inside split - can it be done ?

3. PERLFUNC: split - split up a string using a regexp delimiter

4. Help with split please - or maybe split isn't correct

5. Using split to return a @ without splitting on spaces

6. PERLFUNC: split - split up a string using a regexp delimiter

7. Complicated pattern splitting in split

8. splitting, without losing the thing you split with

9. splitting on newline, not stripping trailing null fields

10. How do I split on | but not \|

11. perlcc does not compile when split to array function is used

12. split a string not only by a single char but also by a string

 

 
Powered by phpBB® Forum Software