472,111 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

help on split

Hi,

I ahve a string
string="ThisAAaAAteAAAAst"
now, I want to split it using "AA" as separator, say
@str = split(/AA/, $string);
however, I want to leave any AA+ as it is, that is,
AAAA and any part of AAAA are not considered as
separator.

Any one knows how to use string pattern match to
do it ?
Of course, I can do it my own way, but I'd like to see
if it's possible in pattern matching.

Thanks

Hai
Jul 19 '05 #1
2 3260
Hai Xu wrote:
I ahve a string
string="ThisAAaAAteAAAAst"
now, I want to split it using "AA" as separator, say
@str = split(/AA/, $string);
however, I want to leave any AA+ as it is, that is, AAAA and any
part of AAAA are not considered as separator.

Any one knows how to use string pattern match to do it ?


One way:

@str = split /(?<!A)AA(?!A)/, $string;

http://www.perldoc.com/perl5.8.0/pod...ended-Patterns

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2
Thank you very much

Hai
"Gunnar Hjalmarsson" <no*****@gunnar.cc> wrote in message
news:Kt********************@newsc.telia.net...
Hai Xu wrote:
I ahve a string
string="ThisAAaAAteAAAAst"
now, I want to split it using "AA" as separator, say
@str = split(/AA/, $string);
however, I want to leave any AA+ as it is, that is, AAAA and any
part of AAAA are not considered as separator.

Any one knows how to use string pattern match to do it ?


One way:

@str = split /(?<!A)AA(?!A)/, $string;

http://www.perldoc.com/perl5.8.0/pod...ended-Patterns

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by stu_gots | last post: by
reply views Thread by Shaggyh | last post: by
9 posts views Thread by Schorschi | last post: by
1 post views Thread by Rahul | last post: by
6 posts views Thread by GHUM | last post: by
4 posts views Thread by rsaharia | last post: by
37 posts views Thread by xyz | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.