How to use regex in DSS Formula replace()?

Antal
Antal Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 88 Neuron

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

Best Answer

Answers

  • JuanE
    JuanE Dataiker, Registered Posts: 45 Dataiker
  • Antal
    Antal Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 88 Neuron

    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

  • Antal
    Antal Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 88 Neuron

    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
    tgb417 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 1,598 Neuron

    @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-across-all/idi-p/16974

    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.

Setup Info
    Tags
      Help me…