Skip to main content
Solved

Insert a space between a number and text in a string

  • April 12, 2018
  • 2 replies
  • 228 views

chris_m
Participant
Forum|alt.badge.img+1

I have some addresses that have been parsed fairly well. However I several thousand that have a letter after the house #, my geocoder requires a space here.

For example I have 123A Main Street I need 123 A Main Street

So I was thinking I could use the StringReplacer transformer to search for [0-9][A-Z], but I don't know what to put in the Replacement Text field.

Best answer by kd

Hi @chris_m

I would capture the house numbers and letters into two different capturing groups using ( ) in regex.

You can reference these afterwards in the replacement text field.

Your Text to match would thus become: ([0-9]+)([a-z])

and your replacement text: \\1 \\2

which basically translates to: (results of first capturing group) <space>(results of the second capturing group)

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Celebrity
  • 2077 replies
  • April 12, 2018

Hi @chris_m,

I tested here in my Workspace with the transformer StringSearch:

Attached the template Workspace - workspace-stringsearch.fmwt

Thanks,

Danilo


Forum|alt.badge.img+1
  • 52 replies
  • Best Answer
  • April 12, 2018

Hi @chris_m

I would capture the house numbers and letters into two different capturing groups using ( ) in regex.

You can reference these afterwards in the replacement text field.

Your Text to match would thus become: ([0-9]+)([a-z])

and your replacement text: \\1 \\2

which basically translates to: (results of first capturing group) <space>(results of the second capturing group)