Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Regex : Limit value of a string

by hippo (Bishop)
on Oct 14, 2015 at 08:48 UTC ( [id://1144829]=note: print w/replies, xml ) Need Help??


in reply to [SOLVED] Regex : Limit value of a string

The regex you are using does not anchor to the end.

use strict; use warnings; use Test::More tests => 4; my $tomatch = 'GigabitEthernet1/0/48'; my $notmatch = 'GigabitEthernet1/0/49'; my $yourgo = qr/(^gi.*)([1-8])(\/)(0)(\/)([1-9]|[1-3][0-9]|4[0-8])/i; my $mygo = qr/(^gi.*)([1-8])(\/)(0)(\/)([1-9]|[1-3][0-9]|4[0-8])$/i; like ($tomatch, $yourgo, "$tomatch matches"); unlike ($notmatch, $yourgo, "$notmatch does not match"); like ($tomatch, $mygo, "$tomatch matches"); unlike ($notmatch, $mygo, "$notmatch does not match");

There's other things you could clean up in the regex and your stipulation of not using a numerical comparison requires justification but this should put you on the right road at least.

Replies are listed 'Best First'.
Re^2: Regex : Limit value of a string
by PtitePomme (Initiate) on Oct 14, 2015 at 10:03 UTC

    Man, thanks for your help! I was pretty sure I tried with the "$" at the end, but obviously not... Thanks a lot!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found