Best answer

Regex / Python code to select all characters except some specials

  • 6 April 2023
  • 5 replies
  • 149 views

Userlevel 1

Hello friends,

 

I try for a long time to use a Regex pattern to extract all characters from a sentence, except some special characters.

Here is an example of the original sentence data :

["https:\/\/www.website.com\/sub_1\/sub_2\/sub_3\/sub_4\/sub_5\/sub_6\/File1.pdf","https:\/\/www.website.com\/sub_1\/sub_2\/sub_3\/sub_4\/sub_5\/sub_6\/File93.pdf","https:\/\/www.website.com\/sub_1\/sub_2\/sub_3\/sub_4\/sub_5\/sub_6\/File83.pdf","https:\/\/www.website.com\/sub_1\/sub_2\/sub_3\/sub_4\/sub_5\/sub_6\/File73.pdf","https:\/\/www.website.com\/sub_1\/sub_2\/sub_3\/sub_4\/sub_5\/sub_6\/File63.pdf","https:\/\/www.website.com\/sub_1\/sub_2\/sub_3\/sub_4\/sub_5\/sub_6\/File53.pdf","https:\/\/www.website.com\/sub_1\/sub_2\/sub_3\/sub_4\/sub_5\/sub_6\/File43.pdf"]

 

My goal is to remove the characters [ ] \ andto keep only the url’s separeted by comma.

I can do it in 4 steps (1st remove [, 2nd remove ], … but my entire zap will have more than 50 steps at the end !

I tried this Python regex :

import re

regex = r"[^][\"]"
 

But output is 0 😕

If anyone have an idea, it should be really friendly !

Brest Regards,

Thommen

icon

Best answer by Troy Tessalone 6 April 2023, 17:33

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

5 replies

Userlevel 7
Badge +14

Hi @Thommen 

Good question.

Try asking AI (ChatGPT) for help: https://chat.openai.com

ChatGPT can generate the JavaScript / Python code to use in a Code step.

Userlevel 1

@Troy Tessalone I’m on ChatGPT for that, just now :-) But it doesn’t work with the code generated, for the moment. I continue to try :-)

Userlevel 7
Badge +14

@Thommen 

Example with JavaScript

You will need to tweak a bit to work with the code formatting that a Zap Code step expects.

 

 

Userlevel 7
Badge +14

@Thommen 

 

CONFIG

 

CODE

let X = inputData.X;

let Y = X.replace(/[\[\]\\"]/g, '');

output = [{X, Y}];

 

RESULTS

 

Userlevel 1

@Troy Tessalone Thank you a lot!