Remove string after delimiter

Solved!
imransaiful17
Level 2
Remove string after delimiter

Hi Team,

Looking for help here on how to remove all string after a delimiter.

For example i have a data with the value: ht/w.domaindomain.c/pathpath

and i want to remove all the strings after the delimiter last '/'

the results would be : ht/w.domaindomain.c

Please assist. Thanks!

0 Kudos
1 Solution
VitaliyD
Dataiker

Hi, 

To add to Manuel's solution. If you already know the pattern, you can use the similar Regex approach but with Find and Replace processor like below:

Screenshot 2021-09-30 at 14.27.44.png

Best,

Vitaliy

View solution in original post

0 Kudos
5 Replies
Manuel
Dataiker Alumni

Hi,

In a Prepare recipe, use the Smart Pattern Builder to extract the text, as explained in this page, https://knowledge.dataiku.com/latest/courses/advanced-data-prep/prepare-recipe/smart-pattern-builder...

I hope this helps.

Best regards

0 Kudos
VitaliyD
Dataiker

Hi, 

To add to Manuel's solution. If you already know the pattern, you can use the similar Regex approach but with Find and Replace processor like below:

Screenshot 2021-09-30 at 14.27.44.png

Best,

Vitaliy

0 Kudos
imransaiful17
Level 2
Author

Thank you both on providing the solutions! It works for me!

0 Kudos
imransaiful17
Level 2
Author

Hi VitaliyD,

Would you be able to explain further on what does the logic really saying?

(^.*)(\/.*) and replace by $1 ?

0 Kudos
VitaliyD
Dataiker

Hi @imransaiful17

With this regex expression, we are forming two groups including everything before the last forward slash and everything after and then taking the second group and output as the value in the cell.

If you are looking for a more detailed explanation of the regex, there are many resources on the internet available. The one I use mostly for regex expression testing is https://regex101.com/. If you copy-paste the expression into the regular expression field, you will see a good explanation of what the expression does in the right pane.

Hope this helps,

Best,

Vitaliy

0 Kudos