in reply to regular expression to match specific members of a bus_name

I still don't really understand the number range you're trying to isolate (use  <code> tags on anything with  [ ] in it, or else  &#91; &#93; HTML entities), but here's something to maybe get started with:

c:\@Work\Perl\monks>perl -wMstrict -le "my @pinList = map {; qq{pce_rx_n$_}, qq{pce_rx_p$_}, qq{pce_tx_n$_}, qq{pce_tx_p$_}, qq{cwx_tx_n${_}_blah}, qq{cwx_rx_p${_}bleh}, } 0 .. 15; ;; my $pre = qr{ pce | cwx }xms; my $trx = qr{ [tr] x }xms; my $np = qr{ [np] }xms; my $n = qr{ \d (?! \d) }xms; ;; my $ok = qr{ \A $pre _ $trx _ $np $n [_a-z]* \z }xms; ;; for my $p (@pinList) { printf qq{'$p' -> %sok \n}, $p =~ $ok ? '' : 'NOT '; } " 'pce_rx_n0' -> ok 'pce_rx_p0' -> ok 'pce_tx_n0' -> ok 'pce_tx_p0' -> ok 'cwx_tx_n0_blah' -> ok 'cwx_rx_p0bleh' -> ok 'pce_rx_n1' -> ok 'pce_rx_p1' -> ok 'pce_tx_n1' -> ok 'pce_tx_p1' -> ok 'cwx_tx_n1_blah' -> ok 'cwx_rx_p1bleh' -> ok 'pce_rx_n2' -> ok 'pce_rx_p2' -> ok 'pce_tx_n2' -> ok 'pce_tx_p2' -> ok 'cwx_tx_n2_blah' -> ok 'cwx_rx_p2bleh' -> ok 'pce_rx_n3' -> ok 'pce_rx_p3' -> ok 'pce_tx_n3' -> ok 'pce_tx_p3' -> ok 'cwx_tx_n3_blah' -> ok 'cwx_rx_p3bleh' -> ok 'pce_rx_n4' -> ok 'pce_rx_p4' -> ok 'pce_tx_n4' -> ok 'pce_tx_p4' -> ok 'cwx_tx_n4_blah' -> ok 'cwx_rx_p4bleh' -> ok 'pce_rx_n5' -> ok 'pce_rx_p5' -> ok 'pce_tx_n5' -> ok 'pce_tx_p5' -> ok 'cwx_tx_n5_blah' -> ok 'cwx_rx_p5bleh' -> ok 'pce_rx_n6' -> ok 'pce_rx_p6' -> ok 'pce_tx_n6' -> ok 'pce_tx_p6' -> ok 'cwx_tx_n6_blah' -> ok 'cwx_rx_p6bleh' -> ok 'pce_rx_n7' -> ok 'pce_rx_p7' -> ok 'pce_tx_n7' -> ok 'pce_tx_p7' -> ok 'cwx_tx_n7_blah' -> ok 'cwx_rx_p7bleh' -> ok 'pce_rx_n8' -> ok 'pce_rx_p8' -> ok 'pce_tx_n8' -> ok 'pce_tx_p8' -> ok 'cwx_tx_n8_blah' -> ok 'cwx_rx_p8bleh' -> ok 'pce_rx_n9' -> ok 'pce_rx_p9' -> ok 'pce_tx_n9' -> ok 'pce_tx_p9' -> ok 'cwx_tx_n9_blah' -> ok 'cwx_rx_p9bleh' -> ok 'pce_rx_n10' -> NOT ok 'pce_rx_p10' -> NOT ok 'pce_tx_n10' -> NOT ok 'pce_tx_p10' -> NOT ok 'cwx_tx_n10_blah' -> NOT ok 'cwx_rx_p10bleh' -> NOT ok 'pce_rx_n11' -> NOT ok 'pce_rx_p11' -> NOT ok 'pce_tx_n11' -> NOT ok 'pce_tx_p11' -> NOT ok 'cwx_tx_n11_blah' -> NOT ok 'cwx_rx_p11bleh' -> NOT ok 'pce_rx_n12' -> NOT ok 'pce_rx_p12' -> NOT ok 'pce_tx_n12' -> NOT ok 'pce_tx_p12' -> NOT ok 'cwx_tx_n12_blah' -> NOT ok 'cwx_rx_p12bleh' -> NOT ok 'pce_rx_n13' -> NOT ok 'pce_rx_p13' -> NOT ok 'pce_tx_n13' -> NOT ok 'pce_tx_p13' -> NOT ok 'cwx_tx_n13_blah' -> NOT ok 'cwx_rx_p13bleh' -> NOT ok 'pce_rx_n14' -> NOT ok 'pce_rx_p14' -> NOT ok 'pce_tx_n14' -> NOT ok 'pce_tx_p14' -> NOT ok 'cwx_tx_n14_blah' -> NOT ok 'cwx_rx_p14bleh' -> NOT ok 'pce_rx_n15' -> NOT ok 'pce_rx_p15' -> NOT ok 'pce_tx_n15' -> NOT ok 'pce_tx_p15' -> NOT ok 'cwx_tx_n15_blah' -> NOT ok 'cwx_rx_p15bleh' -> NOT ok


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: regular expression to match specific members of a bus_name
by boleary (Scribe) on Feb 12, 2016 at 12:48 UTC

    Thanks! Despite the murkiness of my question, you provided the magic I was looking for:

     my $match_str="[tr]x_n1(?!\\d)";

    It was the zero-width negative look-ahead assertion  (?!\d) that I was looking for

    BTW your use of map is spinning my head :) I will also be looking into qr

      qr// is definitely worth knowing about and using in regex composition. And map/grep are quite useful too.


      Give a man a fish:  <%-{-{-{-<