in reply to Help with a small regex
The issue you are having is that you need the entire string to contain no colons, but what you have tested for is actually that it contains non-colon characters. The closest code to your spec would beforeach (@data) { my $match = $_ if !/:/; }
which says that all characters between the start and end of the string are not colons.foreach (@data) { my $match = $_ if /^[^:]*$/; }
Advanced use case, this is exactly the sort of thing grep was made for:
my ($match) = grep !/:/, @data;
Update: Fixed typo in case two; thanks AnomalousMonk.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|