I have been racking my brain to come up with an efficient way to parse a string. I am hoping those more experienced then me can come up with something. I suspect a regexp is the answer if I can come up with the right template but I am not a regexp expert.
I need to parse a string that contains a date (which can have a couple of formats), followed by a location which will have spaces and commas. For example:
$string="1510, Hamm, Westphalia, Germany";
or
$string="1 OCT 1961, New York, N.Y.";
I think the key is to find the year reliably, then separate the 2 strings. What I ultimately need is the following:
$date="1510";
$place="Hamm, Westphalia, Germany";
or
$date="1 OCT 1961";
$place="New York, N.Y.";
The only thing that can be reliabily expected is a 4 digit year, which ends the date part, followed by a comma if there is a location or no comma if there is no location. Can someone help? TIA.
I need to parse a string that contains a date (which can have a couple of formats), followed by a location which will have spaces and commas. For example:
$string="1510, Hamm, Westphalia, Germany";
or
$string="1 OCT 1961, New York, N.Y.";
I think the key is to find the year reliably, then separate the 2 strings. What I ultimately need is the following:
$date="1510";
$place="Hamm, Westphalia, Germany";
or
$date="1 OCT 1961";
$place="New York, N.Y.";
The only thing that can be reliabily expected is a 4 digit year, which ends the date part, followed by a comma if there is a location or no comma if there is no location. Can someone help? TIA.