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?
In reply to Re^3: Regex Modification
by AnomalousMonk
in thread Regex Modification
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |