One thing I do not understand is that it looks as if you are looping through the file, but match against a constant $string.
Also you should be using
in your code, especially if you're just starting with perl. They do help a lot.use strict; use warnings;
In your code there is one thing (if I read it right): Your variable $string starts with an opening parenthesis, but you anchor your match to start without it.
You also have additional blanks around your \s+ matches. You would require 3 blanks to match: one literal one, then one from \s+ and then another literal one. In your string you only have one.
So either change (added quotes around the $string assignment, updated m//) code to
or get rid of the outermost pair of parenthesis.# string to be searched my $string = '(FT CDS complement(join(18028..18116,19351..20668)))'; #search for the first line highlighted in bold if ($string =~ m/^\(FT\s+CDS\s+complement\(join\([0-9.,]+\)\)\)$/) { print 'match' } else { print 'no match' }
cheers, si_lence
In reply to Re: REGEX malfunction
by si_lence
in thread REGEX malfunction
by rayken
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |