- May, 2008 (5)
- June, 2008 (2)
With a little Regular Expression, we can parse almost anything follow a predefined pattern.
Singapore Address is a good example for parsing data with regular expression. The code in this article is produce by me today, feel free to use it for your purpose.
I use PHP for my parser, but it can be port to any other language which support Regular Expression.
I have the following example, I just found it some where from Internet, but it's not important
With some arrangement, I have some varies of the above example:
If anyone have other varies, please comment.
OK, here is the my little parser (in PHP)
// Build result array
return array(
'number' => $matches[0],
'street' => $matches[1],
'roomno' => isset($matches[2]) ? $matches[2] : "",
'building' => isset($matches[3]) ? $matches[3] : "",
'country' => isset($matches[4]) ? $matches[4] : "",
'postal' => isset($matches[5]) ? $matches[5] : ""
);
}
return false;
}
$detail = parse_sin_address($address);
echo "\nNumber: ", $detail['number'];
echo "\nStreet: ", $detail['street'];
echo "\nRoom: ", $detail['roomno'];
echo "\nBuilding: ", $detail['building'];
echo "\nCountry: ", $detail['country'];
echo "\nPostal: ", $detail['postal'];
You will receives: