in reply to Regular Expression - delimiter/spaces problem

G'day demichi,

Welcome to the monastery.

First, some issues with your post:

Taking those assumptions (and other points) into account, this regex achieves what I think you want:

#!/usr/bin/env perl -l use strict; use warnings; my $re = qr{ ^ # start of l +ine (\S+)\s+(\S+)\s+(\S+)\s+ # 3 fields, +no spaces (.+?)\s+ # 1 field, + +/- spaces (\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+) # 7 fields, +no spaces \s* # possible s +paces ($) # end of lin +e }x; print join ';' => /$re/ while <DATA>; __DATA__ PID POLS U(%) POOL_NAME Seq# Num LDEV# H(%) VCAP(%) TYPE PM 003 POLN 0 Bad name with spaces 13453 2 61443 80 - OPEN N 002 POLN 52 DemoSolutions 54068 7 61454 80 - OPEN N

Output:

PID;POLS;U(%);POOL_NAME;Seq#;Num;LDEV#;H(%);VCAP(%);TYPE;PM; 003;POLN;0;Bad name with spaces;13453;2;61443;80;-;OPEN;N; 002;POLN;52;DemoSolutions;54068;7;61454;80;-;OPEN;N;

-- Ken

Replies are listed 'Best First'.
Re^2: Regular Expression - delimiter/spaces problem
by demichi (Beadle) on Feb 15, 2014 at 12:22 UTC
    Hi Ken,

    thanks for your posting. Your regexp works fine! Sorry for my mistakes in my initial post.

    regards deMichi