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

Hello, boleary. Welcome to the Monastery. Like others who have already responded it isn't entirely clear to me what precisely you are trying to achieve. Since you weren't here last week you likely won't have seen an excellent post on How to ask better questions using Test::More and sample data. Please consider taking a moment to read through this and see if you can't provide a piece of sample code in the manner suggested in that article which will likely help both you and us. If you have any comments to make on the meditation itself I'm sure those would also be welcome.

Thanks.

  • Comment on Re: regular expression to match specific members of a bus_name

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 13:26 UTC

    Thanks hippo.. I was not aware of the Test::More library, I do think that it works to explain what I was looking to do pretty well

    I included the tests with the working and non working regex

    #!/usr/bin/perl use strict; use warnings; use Test::More; my $regex = "/pce_rx_n1/"; like( "pce_rx_n1", $regex, "Matching my regex" ); like( "pce_rx_n1_blah", $regex, "Matching my regex" ); # #these fail because my $regex matches n1 and n10 and n13 # unlike( "pce_rx_n13", $regex, "Not Matching my regex" ); unlike( "pce_rx_n10_blah", $regex, "Not Matching my regex" ); #fix the regex with the #zero look-ahead negative assertion $regex = "/pce_rx_n1(?!\\d)/"; like( "pce_rx_n1", $regex, "Matching my regex" ); like( "pce_rx_n1_blah", $regex, "Matching my regex" ); unlike( "pce_rx_n12", $regex, "Not Matching my regex" ); unlike( "pce_rx_n10_blah", $regex, "Not Matching my regex" ); done_testing;

      Thank you - that is much clearer. Here is your code with only the first regex changed and it now passes all the tests. HTH, Hippo.

      #!/usr/bin/perl use strict; use warnings; use Test::More; my $regex = qr/pce_rx_n1\D*$/; like( "pce_rx_n1", $regex, "Matching my regex" ); like( "pce_rx_n1_blah", $regex, "Matching my regex" ); # #these fail because my $regex matches n1 and n10 and n13 # unlike( "pce_rx_n13", $regex, "Not Matching my regex" ); unlike( "pce_rx_n10_blah", $regex, "Not Matching my regex" ); #fix the regex with the #zero look-ahead negative assertion $regex = "/pce_rx_n1(?!\\d)/"; like( "pce_rx_n1", $regex, "Matching my regex" ); like( "pce_rx_n1_blah", $regex, "Matching my regex" ); unlike( "pce_rx_n12", $regex, "Not Matching my regex" ); unlike( "pce_rx_n10_blah", $regex, "Not Matching my regex" ); done_testing;

        That was originally what I was trying for :) somehow I never used the \D*$ though. I do like the qr!