// What follows is a fairly "ergonomic" parser for addresses I got & simplified from mp.xml.
var address = "";
var city = "";
// detect leading ### w w w st
var res = q.match(/^\s*(\d+(\s+\w+)+\s+(st|ave|rd|ln|dr|blvd|cir|ct|pkwy|pl|way|aly|pk|sq|ter|plz|rue|bd))[\s\.,;]*(.*)$/i);
if (res && res[1])
{
address = res[1];
city = res[4];
}
// detect trailing comma or semicolon; prefer this way of finding city
res = q.match(/[\.,;]\s*([^\d][^,;]+)[\s\.,;]*$/i);
if (res && res[1])
{
city = res[1];
address = q.substring(0, res.index);
}
// last resorts: we really want a city
if (city == "")
{
// drop requirement for street number and precise abbreviation and look for street
res = q.match(/^\s*((\w+\s+)+(st|ave|rd|ln|dr|blvd|cir|ct|pkwy|pl|way|aly|pk|sq|ter|plz|street|avenue|road|lane|drive|boulevard|circle|court|parkway|place|loop|alley|park|square|terrace|plaza|mall))[\s\.,;]*(.*)$/i);
if (res && res[1])
{
address = res[1];
city = res[4];
}
// has a number: city is last word
else if (q.match(/^\s*\d/))
{
res = q.match(/(\w+)[\s\.,;]*$/);
city = res[1];
address = q.substring(0, res.index);
}
// otherwise, looks like it doesn't have a street; city is whole thing
else
{
city = q;
address = "";
}
}
document.viamf.strAddress.value = address;
document.viamf.intMapScale.value = size;
document.viamf.strCity.value = city;
submitForm(viamf);
}
]]></script>
<copyright>
The following applies if this file is included and distributed with Dave's Quick Search Deskbar:
Copyright (c) 2002 David Bau; Distributed under the terms of the GNU Public License, Version 2 (http://www.gnu.org/copyleft/gpl.txt)
</copyright>
<created_by>
This search file was initially created on 10/14/02 at 15:04:31
by Dave's Quick Search Deskbar Search Wizard version 0.9.1 (beta),
Copyright (c) 2002 Glenn Carr; Distributed under the terms of the GNU General Public License, Version 2