[Tutor] Help with Re to extract fixed width data fields
Phil Bertram
phil.bertram@clear.net.nz
Fri, 15 Sep 2000 09:40:17 +1200
This is a multi-part message in MIME format.
------=_NextPart_000_0006_01C01EF8.F519B800
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi all,
I have data that is of fixed length but with no deliminaters
eg. 3456Customer9878Product etc etc etc
I have been using a regular expression (in the form as shown below) to =
extract the fields. The real data has over 30 fields so the expression =
is very large.
Is there a better way ?
fields=3Dre.match('(.{4,4})(.{8,8})(.{4,4})(.{7,7})',line,0)=20
Regards
Phil Bertram phil.bertram@clear.net.nz 07 850 9305 025 426 =
825
------=_NextPart_000_0006_01C01EF8.F519B800
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3612.1706"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2>Hi all,</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2>I have data that is =
of fixed length=20
but with no deliminaters</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2>eg.=20
3456Customer9878Product etc etc etc</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2></FONT> </DIV>
<DIV><FONT face=3DVerdana size=3D2>I have been using a regular =
expression (in the=20
form as shown below) to extract the fields. The real data has over 30 =
fields so=20
the expression is very large.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>Is there a better way ?</FONT></DIV>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DVerdana=20
size=3D2>fields=3Dre.match('(.{4,4})(.{8,8})(.{4,4})(.{7,7})',line,0)=20
<BR></FONT></DIV>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DVerdana size=3D2>Regards<BR>Phil=20
Bertram <A=20
href=3D"mailto:phil.bertram@clear.net.nz">phil.bertram@clear.net.nz</A>&n=
bsp; =20
07 850 9305 025 426 =
825</FONT></DIV></BODY></HTML>
------=_NextPart_000_0006_01C01EF8.F519B800--