Regex for finding and discarding whats not needed

Anyone one knows how to lets say find in my example only the numbers between 50-59 and return only those numbers, not the others is there a way to do it in regex

const data = [
{"draw_date":"2022-03-16T00:00:00.000","winning_numbers":"34 42 48 51 56 59","bonus":"6"}
,{"draw_date":"2022-03-12T00:00:00.000","winning_numbers":"12 19 22 34 50 56","bonus":"7"}
,{"draw_date":"2022-03-09T00:00:00.000","winning_numbers":"17 28 29 32 37 40","bonus":"56"}
,{"draw_date":"2022-03-05T00:00:00.000","winning_numbers":"01 11 21 38 39 52","bonus":"44"}
,{"draw_date":"2022-03-02T00:00:00.000","winning_numbers":"19 20 37 41 47 55","bonus":"31"}
,{"draw_date":"2022-02-26T00:00:00.000","winning_numbers":"08 32 43 46 52 58","bonus":"14"}
,{"draw_date":"2022-02-23T00:00:00.000","winning_numbers":"13 15 36 46 53 57","bonus":"58"}
]


data.map( d => {
  const groupData = {}

  let nums = d['winning_numbers']
  console.log(nums.match(/[50-59]/))
})

I’m not sure a regex is the best approach here. Is there a specific reason you want to use a regex?

Personally, I would just split the numbers into an array and filter the array to just numbers between 50-59.

1 Like

yeah haha overthinking! thanks

data.map( d => {
  const groupData = {}

  let nums = d['winning_numbers']
  console.log(nums.split(' ').filter( d => (+d >= 50 && +d < 60)   ))
})

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.