Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: problem using regexp

by Grimy (Pilgrim)
on Jul 27, 2012 at 20:36 UTC ( #984094=note: print w/replies, xml ) Need Help??

in reply to problem using regexp

The problem here is overlapping matches. The space between the first and the second occurence of /a/i is part of both possible matches. Since it is gobbled by the first match, the second /a/i doesn't match.

It is possible to "rewind" your regex by assigning to pos. See 'pos' in perldoc.

#! usr/bin/perl use strict; use warnings; $_=' A a A '; while (/(\s)(a)(\s)/ig) { print "The text matches the pattern '$&' at position " . pos() . " +.\n"; # uncomment this to rewind #pos() = pos() - 1; }

Replies are listed 'Best First'.
Re^2: problem using regexp
by artifact (Novice) on Jul 29, 2012 at 16:05 UTC
    it works!! it also made me learn few other concepts.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://984094]
[1nickt]: Discipulus too easy!
[1nickt]: "The sixth sheik's sixth sheep's sick" (if you are after 'sh' tongue twisters)
[Discipulus]: ok try it in Eatalian ;=)
[Eily]: Discipulus I don't suppose you can do the same for me can you ? :P
[Discipulus]: Eily tongue twister or votes? ;=)
[Eily]: Discipulus turn me into a Bishop
Discipulus abracadabra.. Eily tranformed into a.. shop for bisexual peoples..
[LanX]: Eily don't be sad ... you are the Bishop of our hearts.
[marto]: 1nickt, I just said that in a Sean Connery accent

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2017-09-26 12:07 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (294 votes). Check out past polls.