469,951 Members | 2,625 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,951 developers. It's quick & easy.

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 3197
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 this site, you agree to our Privacy Policy and Terms of Use.