I tend to avoid putting ?, +, *, etc on captures. I don't know if the behaviour is even documented, but the behaviour is as follows:
(...)? Returns undef if it matched 0 items. ((?:...)?) Returns an empty but defined string if it matched 0 items.
You can use defined to test in the first case.
In reply to Re: Special Variables in Regular Expression
by ikegami
in thread Special Variables in Regular Expression
by fiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |