Best answer

Looking for Pattern to extract dates

  • 22 November 2022
  • 6 replies
  • 38 views

Userlevel 1

Hey there, I have an input data that goes like this “Novermber 26th & 27th”

I am looking for a pattern where I could get the output as

1.November 26th 

1.November 27th

Is this possible with patterns? If so how.

Thanks :)

icon

Best answer by GetUWired 28 November 2022, 17:49

View original

6 replies

Userlevel 7
Badge +12

You could do this with 2 patterns. 1 to extract the month and 1 to extract the days. The only downside i see is that you get back a list so Zapier adds some commas where there shouldn’t be and as a result you may need another step to remove the commas and clean it up. 


You could also look at writing some code and doing this with a Code by Zapier step. 


 

 

Userlevel 1

@GetUWired Thanks, there is one problem. I am not seeing the output of the date pattern in other actions. This is what it shows
 

 

 

This is what the test of the action where we extract the date is like

Do you know why this is happening?

 

 

Userlevel 7
Badge +12

I am not sure why that is happening. Another approach would be to use code. (javascript)

 

let inputDate = inputData.dates;
output = {};

let monthMatches = inputDate.match(/January|February|March|April|May|June|July|August|September|October|November|December/g)
let dateMatches = inputDate.match(/\d{1,2}th|st|nd|rd/g)

output.month = Object.assign({},monthMatches)
output.dates = Object.assign({},dateMatches)

 

Userlevel 1

Thanks @GetUWired, that worked. Its awesome that you were able to create this code, how can I learn this so I can do such scripts on my own, this seems very interesting to me.

Userlevel 1

Hey @GetUWired, the code you sent me is not working when the input was this.

So this is the input “December (3rd-17th)”

 

 The output doesn't show “3rd”. This is the output of this action

Do you know why this happens?

 

Userlevel 7
Badge +12

@Fahad.S  Whoops! 
Try changing this line from 

let dateMatches = inputDate.match(/\d{1,2}th|st|nd|rd/g)

to

let dateMatches = inputDate.match(/\d{1,2}(th|st|nd|rd)/g)


As far as how to learn this, Regexr is a great tool for writing Regular Expressions: https://regexr.com/ 
The code is written in Javascript and there are a TON of resources online: https://www.freecodecamp.org/news/learn-javascript-free-js-courses-for-beginners/ 
and once you get used to the lingo Google becomes a great help!

Reply