Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Need A regex

by Anonymous Monk
on Apr 12, 2013 at 05:22 UTC ( #1028283=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I need a regex to match following number

Match No-Match 45123689745812 4514:4549 56378 451:896547899 4514|45698:1245|1245 451:568:652:1236 4518:4569:5698:1256

The MAX numeric allowed is 20 and MIN is 12.I also saw a latest post which was something similar to this , But could not make much of it. Please guide...

Replies are listed 'Best First'.
Re: Need A regex
by CountZero (Bishop) on Apr 12, 2013 at 06:12 UTC
    I think the most easy way to do this is to first delete from your string all ':' and then check if what remains fits /\d{12,20}/


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re: Need A regex
by hdb (Monsignor) on Apr 12, 2013 at 06:24 UTC

    If you refer to Regex Modification, it later turned out that the specification was far more complicated than stated in the initial question, see below. In order to make this more efficient, can you please confirm the exact requirements.

    1. Number seq. with min 9 and max 15 digits. Like 145-1256-2365-789 2. First 3 and Last 3 should be numbers not diffrentiators. Like 123-1 +545645-123 3. Match can also be without a diffrentiator like 123456789147 4. The diffrentiator(same throughout sequence) can come any number of +times between the first and last 3 digits until the min and max lengt +h criteria is satisfied. Like 1213-456-789-1265
Re: Need A regex
by AnomalousMonk (Chancellor) on Apr 12, 2013 at 10:12 UTC

    See this recently posted reply to Regex Modification. It may be helpful. But in any event, CountZero's approach above seems both simple and effective.

    Update: This reply is a later and better version of the reply linked above.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1028283]
Approved by vinoth.ree
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2017-12-17 04:36 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (462 votes). Check out past polls.