in reply to Extracting fields
One sample is not enough, but maybe something like this?
#! perl -slw use strict; my %data = ( 1047633 => '01.12.199100.00.00003 T8 15 SN Y2001.11.200400095.8000071.8500081.454 +001.11.1994(Anaes.)5001.12.1991Metatarsal, 1 of, treatment of fractur +e of' ); my $re_date = qr[\d{2}\.\d{2}\.\d{4}]; my $re_float= qr[\d{5}\.\d{2}]; for my $key ( keys %data ) { my @fields = $data{ $key } =~ m[ ( 20 $re_date $re_float{3} ) ( 40 $re_date \( [^)]+ \) ) ( 50 $re_date .* $ ) ]x; print "'$_'" for @fields; } __END__ P:\test>401374 '2001.11.200400095.8000071.8500081.45' '4001.11.1994(Anaes.)' '5001.12.1991Metatarsal, 1 of, treatment of fracture of'
To explan the regex:
m[ ## Capture, starting with '20', one date, and 3x %8.2 floats ( 20 $re_date $re_float{3} ) ## Capture, starting with '40', one date, '(', non-')' to the ')' ( 40 $re_date \( [^)]+ \) ) ## Capture, '50', a date, everything to the end of line. ( 50 $re_date .* $ ) ]x; ## ignore whitespace.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extracting fields
by kerrya (Novice) on Oct 22, 2004 at 06:05 UTC | |
by BrowserUk (Patriarch) on Oct 22, 2004 at 06:47 UTC |