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