My spec states that a valid account number is 20 characters long and consists of at least one digit followed by spaces (and just spaces, not everything that matches \s). The account number is extracted from a longer string.
I am using Parse::RecDescent to validate the longer string as
record : account address info
account : /trusty regex here/
address : ...
info : ...
There is a lot more to the grammar (about another 200 lines), but this is the bit relevant to my problem.
Everything in record is fixed length.
But I am having trouble writing a one-shot regex to validate this.
I think I want to do this
account : /\d(\d){0,19} {19 - length \1}/
but that doesn't work. I definitely want the account rule to consume 20 characters, so that the address rule starts at the right point.
01234567890123456789
'123 ' # OK
'123 123 ' # NOK
' ' # NOK
'123c ' # NOK
Am I being dense or is this tricky ?
+++++++++++++++++
#!/usr/bin/perl
use warnings;use strict;use brain;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.