Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Regex Modification

by AnomalousMonk (Abbot)
on Apr 10, 2013 at 08:05 UTC ( #1027924=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Regex Modification
in thread Regex Modification

This regex results in consecutive number not being matched like:
Not Matched : 1. 123456789 2.123456789147
Pls tell?

That's because with this regex, a match requires separator characters from the set  [- .] to be present between each three-digit group; this requirement is implied by the specification-by-example in the OP. If you want something like '123456789' to match, try:

>perl -wMstrict -le "my @numbers = ( '123-456-789', '123.456.789', '123 456 789', '123456789', '999-999.999', '999 999-999', '999.999 999', '9999-999-9999', '99-999-99', '0123456789', '999999-999', '999.999999', ); ;; my $diff = qr{ [-. ] }xms; for my $n (@numbers) { my $match = $n =~ m{ (?<! \d) \d{3} ($diff?) \d{3} \1 \d{3} (?! \d) }xms; print $match ? ' ' : 'NO', qq{ match: '$n'}; } " match: '123-456-789' match: '123.456.789' match: '123 456 789' match: '123456789' NO match: '999-999.999' NO match: '999 999-999' NO match: '999.999 999' NO match: '9999-999-9999' NO match: '99-999-99' NO match: '0123456789' NO match: '999999-999' NO match: '999.999999'

I'm puzzled by the presence of '123456789147', which you seem to want to match. This is not in accord with the negative look-around assertions in your OP. Can you please clarify: do you want any sequence of nine or more digits to match? If so, where should the separator characters '- .' fall in relation to the digits?


Comment on Re^3: Regex Modification
Select or Download Code
Re^4: Regex Modification
by Anonymous Monk on Apr 10, 2013 at 08:42 UTC

    All rite I am telling the specification for a match:

    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

    Pls Help...

      All rite I am telling the specification for a match:

      Full knowledge of a problem if often the first step toward a solution!

      Here's an incomplete solution: incomplete because I feel I should be able to match with strings like
          qw(x123-456789123-456x  x123456-789123456x  x123456789123456x)
      and I can't. In addition, the regex I came up with is quite complicated, probably excessively so.

      Be that as it may, everything else seems to work as intended. The critical portions are the $diff, $d_min and $ndn regexes in the  m1() function. I haven't had time to work on this as I would like, but may do so shortly; it's an interesting problem. Sorry for the delay in getting back to you on this. HTH.

      Output:

        Thnx for the reply.. Can pls explain how the pattern matching is being done?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-12-18 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (43 votes), past polls