Regular expression that matches a range of hours within a string

1

I would like to know if it is possible, through a regular expression, with a string containing the date and time, to know if the time is within a given range.

For example:

2016-10-17T08:44:04.000+0000

I would like to know if the time within that string is between 08 and 10 .

    
asked by user1551211 07.11.2016 в 13:15
source

1 answer

2

The most efficient way to solve it would be to record the time separately, allowing you to index through that field and get faster results.

If you still want to do it with a regular expression, you could validate the range from 08 to 10 with the following expression:

/T(?:0[89]|10)/

In this case, the 2 digits that come after the T are compared, making it match any text that contains T08 , T09 or T10 . That is, it coincides with hours between 08:00 and 10:59.

    
answered by 07.11.2016 в 13:34