boleary has asked for the wisdom of the Perl Monks concerning the following question:
trying to build a regular expression to match bus names in a design.
so if the bus is pce_rx_n[15:0], I want to be able to match pce_rx_n1 but not pce_rx_n10...pce_rx_n15
I can't figure out what to put at the end of the regex..
I can't use a dollar at the end of the regex because i also want to match pce_rx_n1_blah
I've tried /pce_rx_n1\D/ but that only works for the pce_rx_n1_blah case
/pce_rx_n1\D?/ doesn't work because no \D will match
I thought this might be the answer... but no dice /pce_rx_n1[\D$]?/
#!/usr/bin/perl -w use strict; #setup bus pins my @pinList=(); for my $i (0..15) { push @pinList,"pce_rx_n$i"; push @pinList,"pce_rx_p$i"; push @pinList,"pce_tx_n$i"; push @pinList,"pce_tx_p$i"; push @pinList,"cwx_tx_n${i}_blah"; push @pinList,"cwx_rx_p${i}bleh"; } # #Here lies the match string I am trying to build #I loosened it up more to match the tx or rx pins with any # pce or cwx prefix #my $match_str="[tr]x_n1[\\D\$]"; # #here is the Fix from Anaomalous Monk using the zero width #negative look-ahead assertion # my $match_str="[tr]x_n1(?!\\d)"; print "match_str=$match_str\n"; #now highlight any matches foreach my $pn (@pinList){ print "$pn"; if ($pn=~/$match_str/i) { print "***"; } print"\n"; }
|
|---|