Help Needed: Splitting Postal Address into Separate Variables in UiPath

Hello UiPath Community,

I am seeking assistance with a project where I need to split a postal address into separate variables to populate a form with individual address components. For example, given an address like:

“Calle Caballero Agro 52, 02148”

But sometimes the clients put the address different, like: Calle Caballero Agro, 52 (02148)… And every client have his own address.

I need to break it down into the following fields:

  • Type of road: Calle
  • Name of the road: Caballero Agro
  • Number of the road: 52
  • Postal Code: 02148

The form I am working with requires each of these components to be entered into separate fields.

Could anyone guide me on how to automate this process using UiPath?

@Carla_Munoz

(?<=\,\s+)\d{4,}

image

\d+(?=\,)

image

(?<=[A-Za-z]+\s).*(?=\s\d+\,)

image

^[A-Za-z]+

image

System.Text.RegularExpressions.Regex.Match(Text,"Regex Pattern").Value

Hope this works for you

1 Like

@Carla_Munoz,

Try this :

addressInput = "Calle Caballero Agro 52, 02148"

postalCode = System.Text.RegularExpressions.Regex.Match(addressInput, "\b\d{5}\b").Value

addressWithoutPostalCode = System.Text.RegularExpressions.Regex.Replace(addressInput, "\b\d{5}\b", "").Trim()

addressParts = addressWithoutPostalCode.Split({",", " "}, StringSplitOptions.RemoveEmptyEntries)

typeOfRoad = addressParts(0)

nameOfRoad = String.Join(" ", addressParts.Skip(1).Take(addressParts.Length - 2))

numberOfRoad = addressParts.Last()

Thanks,
Ashok :slight_smile:

1 Like

Hi @Carla_Munoz

Use below syntax in Assign Activities:

1. Assign Activity -> address = "Calle Caballero Agro 52, 02148"

2. Assign Activity -> cleanAddress = address.Replace("(", "").Replace(")", "").Replace(",", "")

3. Assign Activity -> addressParts = cleanAddress.Split({" "}, StringSplitOptions.RemoveEmptyEntries)

4. Assign Activity -> typeOfRoad = addressParts(0)

5. Assign Activity -> postalCode = addressParts.Last(Function(part) part.Length = 5 AndAlso IsNumeric(part))

6. Assign Activity -> numberOfRoad = addressParts.First(Function(part) IsNumeric(part))

7. Assign Activity -> nameOfRoad = String.Join(" ", addressParts.Skip(1).TakeWhile(Function(part) part <> numberOfRoad AndAlso part <> postalCode))

Variable Datatypes:

Output:
image

Hope it helps!!

1 Like