Skip to main content

I have attribute zip code, where all values looks in this form 12345 how can I transform them into this form 123 45?

My idea was to split it using StringReplacer where I would replace \\d{5} by \\d{3} \\s \\d{2}, however I don't know how can I create new attribute which base on the old zip code attribute (12345).

Are there any other ways to do it?

Hi @vid, I think the StringReplacer is a right way. If you need to preserve the original value, copy the original value to a new attribute with the AttributeCopier, then modify it with the StringReplacer transformer.

Parameters Setting Example:

  • Mode: Replace Regular Expression
  • Text to Replace: (\\d\\d)$
  • Replacement Text: \\1 (a single space and '\\1')


Hi @vid, I think the StringReplacer is a right way. If you need to preserve the original value, copy the original value to a new attribute with the AttributeCopier, then modify it with the StringReplacer transformer.

Parameters Setting Example:

  • Mode: Replace Regular Expression
  • Text to Replace: (\d\d)$
  • Replacement Text:  \1   (a single space and '\1')

Alternatively, you can also use the @ReplaceRegEx function to directly create a new zip code from the original code, in a parameter field such as 'Attribute Value' field in the AttributeCreator. e.g.

 

@ReplaceRegEx(@Value(_original_zip_code),"(.+)(\d\d)$",\1 \2)

 


Hi @vid, I think the StringReplacer is a right way. If you need to preserve the original value, copy the original value to a new attribute with the AttributeCopier, then modify it with the StringReplacer transformer.

Parameters Setting Example:

  • Mode: Replace Regular Expression
  • Text to Replace: (\\d\\d)$
  • Replacement Text: \\1 (a single space and '\\1')

Thank you!

 

 


This would work in an AttributeCreator (or AttributeManager):

@Substring(@Value(zip),0,3) @Substring(@Value(zip),3,2)


Reply