in reply to Validation of unix permissions
I want to match a comma-separated string, with zero or more items, and each item matches a particular regexp,
I presume you're trying to parse valid chmod input such as ug=rwx,o=rx. While your statement allows for a number of alternative permutations, this seems the most likely.
With regard to Update 2 in the OP and given the above understanding of valid input, I believe you may be looking for something akin to:
foreach (split /,/, $perm) { warn "Invalid permission setting: $_" unless /^[ugoa]+=[rwxsS]+$/; }
However, while this is significantly more informative, it doesn't adhere to the spirit of the OP prescription:
The idea is that I'm trying to take a single regexp, and have it match multiple times with an optional separator.
If you just want to detect whether the string contains an invalid permission and you don't need to inform the user of the errant setting, it is possible to use a single regex:
foreach (@perms) { warn "Invalid permission setting detected in $_" unless /^(([u +goa]+=[rwxsS]+)(?(?!$),))+$/; }
|
|---|