On Wed, 2008-09-24 at 18:32 +0200, Rob Coops wrote:
> Hi all,
> 
> I am having some trouble matching the following string:
> 
> "Some text+...:...:...:...:...+some more text"
> 
> The trick is there are two dilimiters in this string the + and the : are
> used to separate the string, the + signifies a part of the string ended and
> the : signifies a sub part of the string has ended.
> 
> Now I need to match this string according to the following rules.
> 
>    - Part 1: 0 to 15 alphanumeric characters (Mandatory)
>    - Part 2: (Mandatory)
>       - Sub part 1 0 to 70 alphanumeric characters (Optional)
>       - Sub part 2 0 to 70 alphanumeric characters (Optional)
>       - Sub part 3 0 to 70 alphanumeric characters (Optional)
>       - Sub part 4 0 to 70 alphanumeric characters (Optional)
>       - Sub part 5 0 to 70 alphanumeric characters (Optional)
>    - Part 3: 0 to 3 alphanumeric characters (Optional)
> 
> I am 100% certain to get all possible variations that these rules allow, so
> how do I match this correctly using a single regex?
> 
> Thanks for any help provided,
> 
> Rob

The question is:  Does '+' and ':' have any other meaning?  If not, you
have context-free data and can use regular expressions to parse it.

my @parts = split /\+/, $line;
my @subparts = split /:/, $parts[1];

You can now validate $parts[0], @subparts, and $parts[2].


-- 
Just my 0.00000002 million dollars worth,
  Shawn

Linux is obsolete.
-- Andrew Tanenbaum


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to