AngelBenitez Posted July 19 Share Posted July 19 (edited) 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 July 19 by AngelBenitez Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 20 Share Posted July 20 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; Quote Link to comment Share on other sites More sharing options...
AngelBenitez Posted July 28 Author Share Posted July 28 Hello @Dan Korn; thank you for assisting me with this. I really appreciate it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.