help on split

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hai Xu

    help on split

    Hi,

    I ahve a string
    string="ThisAAa AAteAAAAst"
    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


  • Gunnar Hjalmarsson

    #2
    Re: help on split

    Hai Xu wrote:[color=blue]
    > I ahve a string
    > string="ThisAAa AAteAAAAst"
    > 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 ?[/color]

    One way:

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



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

    Comment

    • Hai Xu

      #3
      Re: help on split

      Thank you very much

      Hai


      "Gunnar Hjalmarsson" <noreply@gunnar .cc> wrote in message
      news:KtKAb.4112 3$dP1.156917@ne wsc.telia.net.. .[color=blue]
      > Hai Xu wrote:[color=green]
      > > I ahve a string
      > > string="ThisAAa AAteAAAAst"
      > > 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 ?[/color]
      >
      > 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
      >[/color]


      Comment

      Working...