Regular Expression Replace double spaces in a string with one space.

Solved!
RanjithJose
Level 2
Regular Expression Replace double spaces in a string with one space.

Hi, 

I have a string 'Ranjith  Jose' in column 'Name', which has double space between first and last name. I have used Replace prepare recipe.

Matching Mode: Regular Expression

Normalization Mode: Exact

Replacements

\s+ --> No Value (I need to keep one space instead of 'No Value'.)

Please assist.

Thanks,

Ranjith Jose.

 

1 Solution
fchataigner2
Dataiker

Hi,

the Find&Replace step used to trim and ignore whitespace on replacements until quite recently, so if you aren't on a v9.0.3, it's probably the expected behavior.

You should use a "Formula" step, and use replaceChars() or replace(), like

strval("Name").replaceChars("  ", " ")

or

strval("Name").replace(/\s+/, " ")

View solution in original post

4 Replies
fchataigner2
Dataiker

Hi,

the Find&Replace step used to trim and ignore whitespace on replacements until quite recently, so if you aren't on a v9.0.3, it's probably the expected behavior.

You should use a "Formula" step, and use replaceChars() or replace(), like

strval("Name").replaceChars("  ", " ")

or

strval("Name").replace(/\s+/, " ")

RanjithJose
Level 2
Author

Thanks fchataigner2! 

It worked! Appreciate your help ๐Ÿ™‚

0 Kudos
Arun
Level 1

Hi @fchataigner2 

how to apply this formula for all columns.

0 Kudos
Arun
Level 1

@fchataigner2  how to apply this formula for all columns. 

0 Kudos