Regular expression & arrayContains
Hello,
I want to check if a variable contains a letter. For this I want to use a formula in a prepare recipe
Here my code :
if(arrayContains([A-Z], strval('name_var')),1,2)
Output is always '2' even when there is a letter in the variable i'm checking
Thank you, Olivier
Best Answer
-
Ignacio_Toledo Dataiku DSS Core Designer, 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: 415 Neuron
You are right, I forgot the '.*' at the end of the expression.
Happy to help and have a great week! Ignacio
Answers
-
Ignacio_Toledo Dataiku DSS Core Designer, 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: 415 Neuron
Hi @OlivierAb
My impression from the documentation is that arrayContains doesn't work with regular expressions, which is what you are trying to do apparently.
What might work is this:
if(arrayLen(match(column, ".*([A-Za-z])")) > 0, 1, 2)
where you should replace column with the name of your column of interest.
If I understood your problem wrongly please let me know! Cheers
-
Thanks a lot Ignacio !
it works with just a little adjustment. Indeed, ".*" is missing
the final working formula is "if(arrayLen(match(column, ".*([A-Za-z]).*")) > 0, 1, 2)"
Thanks again for your reactivity, Olivier