Jump to content

Fixing Cardinal Directions, Roads, and Suites in Addresses


AngelBenitez

Recommended Posts

Hello,

I need help creating a rule that fixes multiple parts of an address. I need assistance fixing variations in the inputs for cardinal directions in an address, road in an address, and suite if there is a suite number in the address.

I have included examples that way the field might be inputted and the output I would like the rule to spit out. I want the rule to combine all directions, roads, and suite variations provided in the examples.

Input

  • 512 N Elm Ave, Ste. 200, Meadowville, NY 12345
  • 512 N. Elm Ave, Sut. 200, Meadowville, NY 12345
  • 512 North Elm Ave., Suite 200, Meadowville, NY 12345

Output

  • 512 North Elm Avenue, Suite 200, Meadowville, NY 12345

 

 

Input

  • 512 E Elm St, Ste. 200, Meadowville, NY 12345
  • 512 E. Elm St., Sut. 200, Meadowville, NY 12345
  • 512 East Elm Street, Suite 200, Meadowville, NY 12345

Output

  • 512 East Elm Street, Suite 200, Meadowville, NY 12345

 

 

Input

  • 512 W Elm Bl, Meadowville, NY 12345
  • 512 W. Elm Bl., Meadowville, NY 12345
  • 512 West Elm Blvd, Meadowville, NY 12345

Output

  • 512 East Elm Boulevard, Meadowville, NY 12345

 

If anyone can assist me with this, I would greatly appreciate it.

Edited by AngelBenitez
Link to comment
Share on other sites

This is another "unmaking the soup" kind of thing, but it's doable.  Probably the easiest thing is to just have a list of substitutions to apply to the entire string of text.  And you'll want to use regular expressions to match whole words, and not just replace, say, every E that's part of another word with East.  A regular expression can also be told to match the abbreviation either with or without the trailing dot/period.  Something like this:

var subs = {
    N: "North",
    S: "South",
    E: "East",
    W: "West",
    Ave: "Avenue",
    Bl: "Boulevard",
    Blvd: "Boulevard",
    St: "Street",
    Ste: "Suite",
    // etc., add more as needed
    };

var address = "512 N Elm Blvd., Ste. 200, Meadowville, NY 12345"; // or Field("Address") etc.

for (var s in subs)
{
    var re = new RegExp("\\b(" + s + "\\b\\.?)", "g"); // word boundaries, and zero or one dot/period
    address = address.replace(re, subs[s]);
}

return address;
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...