Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Re: not so simple regex problem

Reply
Thread Tools

Re: not so simple regex problem

 
 
nobull@mail.com
Guest
Posts: n/a
 
      07-09-2003
"dw" <(E-Mail Removed)> wrote in message news:<BGWNa.4538$(E-Mail Removed)>...
> "Joe Landman" <(E-Mail Removed)> 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 <(E-Mail Removed)>
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple regex not working John Perl Misc 5 09-14-2008 05:27 PM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
regex bug (comments within regex not as robust) kg.google@olympiakos.com Perl Misc 3 10-27-2005 07:21 PM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments