Go Back   Velocity Reviews > Newsgroups > PERL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

PERL - Re: not so simple regex problem

 
Thread Tools Search this Thread
Old 07-09-2003, 06:10 PM   #1
Default Re: not so simple regex problem


"dw" <> wrote in message news:<BGWNa.4538$>...
> "Joe Landman" <> wrote in message
> newsan.2003.07.06.14.15.09.164093@scalableinform atics.com...


> > 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...0news.ox.ac.uk

This newsgroup does not exist (see FAQ). Please do not start threads
here. Please do respond to questions here without not pointing this
out.


nobull@mail.com
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump