Skip to main content
Best answer

Looking for Pattern to extract dates

  • November 22, 2022
  • 6 replies
  • 457 views

Forum|alt.badge.img

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 :)

Best answer by GetUWired

@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!

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

6 replies

GetUWired
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • November 22, 2022

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. 


 

 


Forum|alt.badge.img
  • Author
  • Beginner
  • November 22, 2022

@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?

 

 


GetUWired
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • November 23, 2022

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)

 


Forum|alt.badge.img
  • Author
  • Beginner
  • November 23, 2022

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.


Forum|alt.badge.img
  • Author
  • Beginner
  • November 24, 2022

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?

 


GetUWired
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • Answer
  • November 28, 2022

@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!