Need a regular expression to parse a text body
Posted
by Ali
on Stack Overflow
See other posts from Stack Overflow
or by Ali
Published on 2010-03-27T06:21:55Z
Indexed on
2010/03/27
6:23 UTC
Read the original article
Hit count: 479
php
|regular-expression
Hi guys, I need a regular expression to parse a body of text. Basically assume this that we have text files and each of which contains random text but within the text there would be lines in the following formats - basically they are a format for denoting flight legs.
eg:
13FEB2009 BDR7402 1000 UUBB 1020 UUWW FLT
This line of text is always on one line
The first word is a date in the format DDMMMYYYY
Second word could be of any length and hold alphanumeric characters
third word is the time in format HHMM - its always numeric
fourth word is a location code - its almost always just alphabets but could also be alphanumeric
fifth word is the arrival time in format HHMM - its always numeric
sixth word is a location code - its almost always just alphabets but could also be alphanumeric
Any words which follow on the same line are just definitions
A text file may contain among lots of random text information one or more such lines of text.
I need a way to be able to extract all this information i.e just these lines within a text file and store them with their integral parts separated as mentioned in an associative array so I have something like this:
array('0'=>array('date'=>'', 'time-dept'=>'', 'flightcode'=>'',....))
I'm assuming regular expressions would be in order here. I'm using php for this - would appreciate the help guys :)
© Stack Overflow or respective owner