The data you posted, does correctly match your regular expression for width. So if it's not working for you, then there's probably something else important in your code that you've neglected to tell us.
One possibility is that your input data actually contains trailing whitespace on the Width line. You don't account for leading or trailing whitespace in your regular expression.
The Descr regular expression isn't going to match though.
Example follows. Don't copy and paste because it may be whitespace-sensitive. Use the "download" link which PerlMonks provides underneath the code...
while (<DATA>) { chomp; my $line = $_; if ($line =~ m/^Width[\s]*\=[\s]*\d+$/) { printf "Found width: \"%s\"\n", $line; } elsif ($line =~ m/^Descr[\s]*-[\s]*[\w]+$/) { printf "Found descr: \"%s\"\n", $line; } else { printf "Garbage found: \"%s\" \n",$line; } } __DATA__ Width = 32 <uart0_rx_data : 16'h0000> Descr - "This is Register1 comment" # f_name bit_pos RESERVED 31:8 RXDATA 5:0 </uart0_rx_data>
In reply to Re: Regular Expression
by tobyink
in thread Regular Expression
by pramod
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |