Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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...

Comment on Need A regex
Download Code
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}/

    CountZero

    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 (Prior) 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 (Abbot) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1028283]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-12-19 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (71 votes), past polls