in reply to check if string is valid with special cases
TIMTOWTDI; personally I'd write:
die "invalid format: $string" unless $string=~/\A[^,]+(?:,[^,]+){5}\z/;
Update: Note your specification is a bit unclear, you say "each one of the substrings can contain whatever symbol there is" but then later on say that the strings can't* contain commas. What about, for example, "1,2,3, ,5,6" (which the above regex will call valid)? See also Re: How to ask better questions using Test::More and sample data.
* Update 2: Sorry, I misunderstood your post, you're saying the strings can contain commas. See my reply below.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: check if string is valid with special cases
by ovedpo15 (Pilgrim) on May 15, 2018 at 10:30 UTC | |
by haukex (Archbishop) on May 15, 2018 at 10:58 UTC | |
by ovedpo15 (Pilgrim) on May 15, 2018 at 11:21 UTC | |
by ovedpo15 (Pilgrim) on May 15, 2018 at 11:09 UTC | |
by haukex (Archbishop) on May 15, 2018 at 11:17 UTC |
In Section
Seekers of Perl Wisdom