Survey banner
Share your feedback on the Dataiku documentation with this 5 min survey. Thanks! TAKE THE SURVEY

How to use regex in DSS Formula replace()?

Solved!
Antal
How to use regex in DSS Formula replace()?

I'm trying to use a regex in a replace() using the Formula processor in a prepare recipe.

According to the documentation/docstring this should work, but I can't get it to recognize the text to replace parameter as a regex and not as literal text.

I'm using a formula as below. How can I get the formula language to interpret "[nN]ext" as a regex and search/replace accordingly? It's driving me crazy 🙂

replace(column1, "[nN]ext", "previous")


Operating system used: AWS Linux

1 Solution
AdrienL
Dataiker

Hi,

According to the documentation, the replace method requires to use /regex/ if you want a regex replacement, otherwise it's a string replacement.

Try with 

replace(column1, /[nN]ext/, "previous")

View solution in original post

0 Kudos
5 Replies
JuanE
Dataiker

Try this:

regex.png

 

0 Kudos
Antal
Author

Yes, that does work.

But in my specific use case I want to replace the regex with the value from another column, which you can't do with the Find/replace processor 😕

Thanks for the quick reply, though

0 Kudos
AdrienL
Dataiker

Hi,

According to the documentation, the replace method requires to use /regex/ if you want a regex replacement, otherwise it's a string replacement.

Try with 

replace(column1, /[nN]ext/, "previous")
0 Kudos
Antal
Author

Yes, that's it! Thanks very much

It wasn't clear to me from the documentation that the slashes were part of the required syntax. Reading it again with this knowledge, kit makes sense.
Maybe a bit more elaborate explanation in the docs would be good.

tgb417

@Antal ,

I agree regex can be a super powerful feature in Dataiku DSS. But the syntax and use can be very varied depending on where you are in the system. Things have gotten better over the years, However, I agree that the documentation regarding the use of regex has been challenging.  

So I created a product idea around regex in DSS.

https://community.dataiku.com/t5/Product-Ideas/Standardize-the-syntax-for-regular-expressions-regex-...

I’d like to invite you (and anyone else reading this post) to vote on that idea if you have not already done so and see value in it.  I’d also invite you to add some comments to that post around this situation or create your own product idea regarding regex if you have another take on this. 

Thanks for sharing your challenge. 

--Tom
0 Kudos

Labels

?
Labels (2)

Setup info

?
A banner prompting to get Dataiku