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; }
In reply to Re: problem using regexp
by Grimy
in thread problem using regexp
by artifact
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |