Parsing addresses into individual pieces has come up before on the forum and I've run across someone who may have created a good solution using regular expressions here. The attached project file has this person's C# code, some sample data, and my lame attempt to make it run in C#. My scripting skills have weakened and I don't know C# at all. Might someone be willing to help me with the code. Thanks. //C# using Manifold.Interop.Scripts; using M = Manifold.Interop; class Script { const string AddressTable = "AddressTable"; const string preDirections = "S W|SW|S E|SE|N W|NW|N E|NE|N|E|W|S"; // Suffixes taken from USPS website: http://pe.usps.gov/text/pub28/28apc_002.htm const string suffixes = "ALLEY|ALLEE|ALY|ALLEY|ALLY|ALY|ANEX|ANEX|ANX // deleted other suffixes for forum formatting reasons; see map file // Unit designators taken from USPS website: http://pe.usps.gov/text/pub28/28c2_003.htm const string unitDesignators = "APARTMENT|APT|BUILDING|BLDG|FLOOR|FL|SUITE|STE|UNIT|UNIT|ROOM|RM|DEPARTMENT|DEPT|SPC"; static void Main() { M.Application app = Context.Application; M.Document doc = (M.Document)app.ActiveDocument; M.ComponentSet comps = (M.ComponentSet)doc.ComponentSet; M.Table table = (M.Table)comps[AddressTable]; foreach (M.Record rec in Table.RecordSet) { var pattern = string.Format( @"^((?<StreetNumber>[0-9]*)(?: ))*((?<PreDirection>({0}))(?! ({1}) ($|({2})))(?: ))?(?<StreetName>(.* (({1}) )?(?=({1}))|(PO|P O) (BX|BOX) [0-9]*))(?: )?((?<StreetSuffix>{1})($|(?: )))?((?<PostDirection>{0})(?: ))?((?<UnitDesignator>{2}))?((?: )(?<SecondaryNumber>[0-9]*))?", preDirections, suffixes, unitDesignators); var match = new Regex(pattern).Match(line); if (match.Success) { var streetNumber = match.Groups["StreetNumber"]; var preDirection = match.Groups["PreDirection"]; var streetName = match.Groups["StreetName"]; var streetSuffix = match.Groups["StreetSuffix"]; var postDirection = match.Groups["PostDirection"]; var unitDesignator = match.Groups["UnitDesignator"]; var secondaryNumber = match.Groups["SecondaryNumber"]; } else } } } Attachments: Address parser.map
|