By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,658 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,658 IT Pros & Developers. It's quick & easy.

help on split

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.