Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Regular Expression

by tobyink (Canon)
on Jun 27, 2012 at 11:48 UTC ( [id://978626]=note: print w/replies, xml ) Need Help??


in reply to Regular Expression

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>
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://978626]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found