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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regex Modification
by Anonymous Monk on Apr 10, 2013 at 08:42 UTC | |
by AnomalousMonk (Archbishop) on Apr 12, 2013 at 10:09 UTC | |
by Anonymous Monk on Apr 12, 2013 at 12:35 UTC | |
by AnomalousMonk (Archbishop) on Apr 14, 2013 at 07:13 UTC | |
by AnomalousMonk (Archbishop) on Apr 16, 2013 at 10:02 UTC | |
by AnomalousMonk (Archbishop) on Apr 13, 2013 at 20:07 UTC |