Going from
print "$1\n" if m|((?:\w+/){4})|;
to
print "$1\n" if m|((?:\w+/){0,4})|;
gets you halfway there. Add a '?':
print "$1\n" if m|((?:\w+/?){0,4})|;
and there you are.
'{4}' means match exactly 4 times, whereas '{0,4}' means match up to 4 times. The '?' makes the '/' optional.
In reply to Re: regex greedy range
by ikegami
in thread regex greedy range
by johnnywang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |