![]() |
|
|
|||||||
![]() |
PERL - Re: not so simple regex problem |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
"dw" <> wrote in message news:<BGWNa.4538$>...
> "Joe Landman" <> wrote in message > news > > 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 |
|
|