in reply to problem using regexp
if (@vars= /(\s)(a)(\s)/ig){ ... }
Another approach to handling overlapping matches (and, IMHO, better because less error-prone and better integrated into the general regex expression than the manipulation of pos) is the use of a look-ahead assertion to wrap capturing groups: see "(?=pattern)" in the Look-Around Assertions sub-section of perlre Extended Patterns. Replacing
/(\s)(a)(\s)/ig
with
/(?=(\s)(a)(\s))/ig
in the code quoted above from the OP produces the desired capture (tested).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem using regexp
by artifact (Novice) on Jul 29, 2012 at 16:15 UTC |