batcater98
Programmer
I need some assistance with reg/exp in regards to splitting up a string and putting items from it into variables
I have a flat file that as lines and lines of data that follow the same pattern throught and I am writing a routine to pull out data elements from each line and insert them into a database.
Example Line from file:
alliancebase.log,Wed 16May07 08:00:48,42id5485,3228 bytes
I want to parse through the file line by line extracting the following.
$Location = alliance (Everything from base to front of line)
$date = YYYY-MM-DD (Want to convert Wed 16May07 to this format)
$time = HH:MM:SS (Extract Time as is)
$id = id (42id5485 is alwasy ##CC#### in format want to pull the two Char CC from this section CC could be any two characters but will alwasy be two characters and preceeded by two numbers and followed by 4 numbers)
$number = 5485 (this could be any 4 numers but will always be 4 numbers following the id)
$size = 3228 (this number will vary, but will always be followed by the words bytes)
Commas will always seperate the fields in this fashion.
If someone could give me an example of how I could piece this string out I would greatly appricate it.
Thanks,
Ad.
I have a flat file that as lines and lines of data that follow the same pattern throught and I am writing a routine to pull out data elements from each line and insert them into a database.
Example Line from file:
alliancebase.log,Wed 16May07 08:00:48,42id5485,3228 bytes
I want to parse through the file line by line extracting the following.
$Location = alliance (Everything from base to front of line)
$date = YYYY-MM-DD (Want to convert Wed 16May07 to this format)
$time = HH:MM:SS (Extract Time as is)
$id = id (42id5485 is alwasy ##CC#### in format want to pull the two Char CC from this section CC could be any two characters but will alwasy be two characters and preceeded by two numbers and followed by 4 numbers)
$number = 5485 (this could be any 4 numers but will always be 4 numbers following the id)
$size = 3228 (this number will vary, but will always be followed by the words bytes)
Commas will always seperate the fields in this fashion.
If someone could give me an example of how I could piece this string out I would greatly appricate it.
Thanks,
Ad.