Skip to main content
Best answer

Troubleshoot error in Python code step to Extract Data From Random String

  • May 26, 2021
  • 4 replies
  • 502 views

Hi,

I am attempting to use Code by Zapier, Python, to extract a specific set of numbers in sequence from a random string of text. The set of numbers will start with four leading zeros. The Python code I am using is adapted from the following which I created in a Python compiler;

 

str = "body of SMS 5PM 9PM 2AM 4 8 2 00001124"
#search using regex
x = re.findall('0000+[0-9]+[0-9]',str)
print('%.8s' %x[0])

 

The output from the above is 00001124, which is perfect.

 

 

 

In Code by Zapier Set up Action, I have the following:

 

The error I am receiving is this:

The objective is to search the entire string and only output the eight digits with four leading zeros. Thanks in advance.

 

 

Best answer by Troy Tessalone

@Ty.

If using a Python Code step, the code would look like this:

 

Output

 

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

4 replies

Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • May 26, 2021

Hi @Ty. 

Try using the Formatter > Text > Extract Pattern instead: https://zapier.com/help/create/format/find-text-with-regular-expressions-in-zaps

 

Output using the settings show below in the screenshots.

 

Try these settings

 


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • May 26, 2021

@Ty.

If you use JavaScript Code step, the code would look like this:

 

Output

 


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • Answer
  • May 26, 2021

@Ty.

If using a Python Code step, the code would look like this:

 

Output

 


  • Author
  • New
  • May 27, 2021

Troy!

…. A million thanks for your response, and explanation of the various methods to use. Also, it’s a pleasure interacting with you again!