Re: not so simple regex problem

Discussion in 'Perl' started by nobull@mail.com, Jul 9, 2003.

  1. Guest

    "dw" <> wrote in message news:<BGWNa.4538$>...
    > "Joe Landman" <> wrote in message
    > news:p...


    > > I have a string
    > >
    > > $b="1" x 10;
    > >
    > > I want to match on pairs of 1's. For this example, there would
    > > be 9 pairs of 1's, e.g.
    > >
    > > 1111111111 : b
    > > 11 : pair 1
    > > 11 : pair 2
    > > 11 : pair 3
    > > .
    > > .
    > > .
    > > 11 : pair 8
    > > 11 : pair 9
    > >
    > > I had originally thought that the following would work:
    > >
    > > my @ones = ($b =~ /11/g);
    > >
    > > Not the case. This gives only 5 pairs. The search continues
    > > from the end of the last match. I need to to continue from the
    > > next character after the matched pattern in the $b.

    >
    > my @ones = ($b =~ /1(?=1)/g);
    >
    > However, you @ones array will now have '1' instead of '11' for each element.
    > But, this will answer your original question of how to get it to identify
    > that there are 9 matches.


    Ah, what goes arround comes arround. I recall giving a similar answer
    to this question a few years ago. Someone else pointed out that m//g
    is smary wrt zero-width matches so you can do:

    my @ones = $b =~ /(?=(11))/g;

    See thread following message <>
    http://groups.google.com/groups?selm=

    This newsgroup does not exist (see FAQ). Please do not start threads
    here. Please do respond to questions here without not pointing this
    out.
    , Jul 9, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phillip Vong

    Simple Validation Problem Using Regex

    Phillip Vong, Oct 4, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    376
    Phillip Vong
    Oct 4, 2006
  2. crybaby
    Replies:
    3
    Views:
    238
    Erik Jones
    Sep 21, 2007
  3. Replies:
    3
    Views:
    726
    Reedick, Andrew
    Jul 1, 2008
  4. Replies:
    3
    Views:
    155
    Paul Lalli
    Oct 27, 2005
  5. John

    simple regex not working

    John, Sep 13, 2008, in forum: Perl Misc
    Replies:
    5
    Views:
    110
    John Bokma
    Sep 14, 2008
Loading...

Share This Page