Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Regex for matching dotted numbers

by AppleFritter (Vicar)
on Jul 21, 2014 at 10:38 UTC ( [id://1094452]=note: print w/replies, xml ) Need Help??


in reply to Regex for matching dotted numbers

Is it intentional that the last one's only got three parts to it? Anyhow, here's one regex that'll work:

/^(?:[\dx]{1,3}\.){0,3}[\dx]{1,3}$/

This will match between 1 and 4 blocks, each consisting of 1 to 3 digits or x's, separated by periods.

Are you dealing with IP addresses there? If so, you may also be interested in Net::IP::Match, Net::IP::Match::* and Net::IP::CMatch.

EDIT: the OP both edited his post and changed the examples of strings he'd like to match after I posted the above. For reference, this was the original post, in its entirety:

I am trying to have a Regex for a dotted number format as shown below

  • 8.1xx.x.x
  • 9.0.3xx.x
  • 9.0.4xx.x
  • . . .
  • 9.1xx.x

So any thoughts how I can make a generic regex for matching all these patterns.

Replies are listed 'Best First'.
Re^2: Regex for matching dotted numbers
by techman2006 (Beadle) on Jul 21, 2014 at 10:46 UTC

    Basically these are version number for a product. So the series can be as given below

    • 8.1.1
    • 8.100.1
    • 9.0.300.1
    • 9.0.301.1
    • 9.0.400.1
    • 9.0.401.1
    • 9.1.0.0
    • 9.100.1.0

    So I need to make sure that if the version matches above then I need to skip running a particular script else run it.

      Please don't make substantial changes to your original posts in a way that makes answers you already received not make sense anymore. Instead, add an addendum to your post to clarify.

      Now, that said, what exactly is it you want to do now? You've got a list of version numbers and a version you want to match against them, and you want to run a particular script unless that version is on your list. So why not simply do exactly that in Perl?

      foreach (@versions) { unless($_ eq $version) { runscript(...); } }

      Or, more idiomatically:

      runscript(...) foreach (grep { $_ ne $version } @versions);

        Sorry for updating the question at random. By the time I went clear on my problem statement there was an reply.

        Basically I am looking for a generic solution that if the version string matches with the version I am looking then run a flow in the script else skip it.

        So having a look up array will not help as there can any version in that format in future I need to update the array every time. That I don't want.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found