Match all timecodes between two timecodes









up vote
3
down vote

favorite
1












I'm trying to generate multiple routes that are all based on timecodes of a video. One same route is used throughout a certain time frame.



Is it possible with regex to get all values between (and including) two timecodes?



Some regex do compare numbers. This one matches all numbers greater than 954.



/[1-9]d3,|9[6-9]d|9[5-9]2/g


But is it possible to compare the followings ? (By replacing the naive comparisons by regular expressions)



00:00<00:01 // should get 00:00 and 00:01 but not 00:02
00:00<00:02 // should get 00:00, 00:01 and 00:02


Additional context: Using path-to-regexp I can do things like /:lang(en|es) to match english or spanish. I was experimenting on passing in /:timecode(regexp) to match any timecode between two timecodes.



This would provide one same route route for /00:00 and /00:01










share|improve this question



















  • 1




    I suggest you convert timecodes to time variable, then you can easily do the math.
    – Poul Bak
    Nov 8 at 23:02










  • What programming language do you use?
    – Poul Bak
    Nov 8 at 23:11











  • Your linked regex matches a time range rather than times, can you clarify? Anyway, given a time start and a time end, you need more than pure regex to match all the times between. However, a language could generate a regex that matches them (but would probably do a better job without regex)
    – Aaron
    Nov 8 at 23:14






  • 3




    The regex for the general case of a range is very ugly, long and painful to write. Regex is not the best tool for the job. I recommend converting to a single integer value (for example, the number of seconds since midnight, or since the last hour, etc) and check if the value is within low/high values using math.
    – Bohemian
    Nov 8 at 23:25






  • 1




    What exactly is your question? Do you want to know how to create such regex?
    – JojOatXGME
    Nov 9 at 23:00














up vote
3
down vote

favorite
1












I'm trying to generate multiple routes that are all based on timecodes of a video. One same route is used throughout a certain time frame.



Is it possible with regex to get all values between (and including) two timecodes?



Some regex do compare numbers. This one matches all numbers greater than 954.



/[1-9]d3,|9[6-9]d|9[5-9]2/g


But is it possible to compare the followings ? (By replacing the naive comparisons by regular expressions)



00:00<00:01 // should get 00:00 and 00:01 but not 00:02
00:00<00:02 // should get 00:00, 00:01 and 00:02


Additional context: Using path-to-regexp I can do things like /:lang(en|es) to match english or spanish. I was experimenting on passing in /:timecode(regexp) to match any timecode between two timecodes.



This would provide one same route route for /00:00 and /00:01










share|improve this question



















  • 1




    I suggest you convert timecodes to time variable, then you can easily do the math.
    – Poul Bak
    Nov 8 at 23:02










  • What programming language do you use?
    – Poul Bak
    Nov 8 at 23:11











  • Your linked regex matches a time range rather than times, can you clarify? Anyway, given a time start and a time end, you need more than pure regex to match all the times between. However, a language could generate a regex that matches them (but would probably do a better job without regex)
    – Aaron
    Nov 8 at 23:14






  • 3




    The regex for the general case of a range is very ugly, long and painful to write. Regex is not the best tool for the job. I recommend converting to a single integer value (for example, the number of seconds since midnight, or since the last hour, etc) and check if the value is within low/high values using math.
    – Bohemian
    Nov 8 at 23:25






  • 1




    What exactly is your question? Do you want to know how to create such regex?
    – JojOatXGME
    Nov 9 at 23:00












up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





I'm trying to generate multiple routes that are all based on timecodes of a video. One same route is used throughout a certain time frame.



Is it possible with regex to get all values between (and including) two timecodes?



Some regex do compare numbers. This one matches all numbers greater than 954.



/[1-9]d3,|9[6-9]d|9[5-9]2/g


But is it possible to compare the followings ? (By replacing the naive comparisons by regular expressions)



00:00<00:01 // should get 00:00 and 00:01 but not 00:02
00:00<00:02 // should get 00:00, 00:01 and 00:02


Additional context: Using path-to-regexp I can do things like /:lang(en|es) to match english or spanish. I was experimenting on passing in /:timecode(regexp) to match any timecode between two timecodes.



This would provide one same route route for /00:00 and /00:01










share|improve this question















I'm trying to generate multiple routes that are all based on timecodes of a video. One same route is used throughout a certain time frame.



Is it possible with regex to get all values between (and including) two timecodes?



Some regex do compare numbers. This one matches all numbers greater than 954.



/[1-9]d3,|9[6-9]d|9[5-9]2/g


But is it possible to compare the followings ? (By replacing the naive comparisons by regular expressions)



00:00<00:01 // should get 00:00 and 00:01 but not 00:02
00:00<00:02 // should get 00:00, 00:01 and 00:02


Additional context: Using path-to-regexp I can do things like /:lang(en|es) to match english or spanish. I was experimenting on passing in /:timecode(regexp) to match any timecode between two timecodes.



This would provide one same route route for /00:00 and /00:01







javascript regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 23:08

























asked Nov 8 at 22:51









Asten Mies

513110




513110







  • 1




    I suggest you convert timecodes to time variable, then you can easily do the math.
    – Poul Bak
    Nov 8 at 23:02










  • What programming language do you use?
    – Poul Bak
    Nov 8 at 23:11











  • Your linked regex matches a time range rather than times, can you clarify? Anyway, given a time start and a time end, you need more than pure regex to match all the times between. However, a language could generate a regex that matches them (but would probably do a better job without regex)
    – Aaron
    Nov 8 at 23:14






  • 3




    The regex for the general case of a range is very ugly, long and painful to write. Regex is not the best tool for the job. I recommend converting to a single integer value (for example, the number of seconds since midnight, or since the last hour, etc) and check if the value is within low/high values using math.
    – Bohemian
    Nov 8 at 23:25






  • 1




    What exactly is your question? Do you want to know how to create such regex?
    – JojOatXGME
    Nov 9 at 23:00












  • 1




    I suggest you convert timecodes to time variable, then you can easily do the math.
    – Poul Bak
    Nov 8 at 23:02










  • What programming language do you use?
    – Poul Bak
    Nov 8 at 23:11











  • Your linked regex matches a time range rather than times, can you clarify? Anyway, given a time start and a time end, you need more than pure regex to match all the times between. However, a language could generate a regex that matches them (but would probably do a better job without regex)
    – Aaron
    Nov 8 at 23:14






  • 3




    The regex for the general case of a range is very ugly, long and painful to write. Regex is not the best tool for the job. I recommend converting to a single integer value (for example, the number of seconds since midnight, or since the last hour, etc) and check if the value is within low/high values using math.
    – Bohemian
    Nov 8 at 23:25






  • 1




    What exactly is your question? Do you want to know how to create such regex?
    – JojOatXGME
    Nov 9 at 23:00







1




1




I suggest you convert timecodes to time variable, then you can easily do the math.
– Poul Bak
Nov 8 at 23:02




I suggest you convert timecodes to time variable, then you can easily do the math.
– Poul Bak
Nov 8 at 23:02












What programming language do you use?
– Poul Bak
Nov 8 at 23:11





What programming language do you use?
– Poul Bak
Nov 8 at 23:11













Your linked regex matches a time range rather than times, can you clarify? Anyway, given a time start and a time end, you need more than pure regex to match all the times between. However, a language could generate a regex that matches them (but would probably do a better job without regex)
– Aaron
Nov 8 at 23:14




Your linked regex matches a time range rather than times, can you clarify? Anyway, given a time start and a time end, you need more than pure regex to match all the times between. However, a language could generate a regex that matches them (but would probably do a better job without regex)
– Aaron
Nov 8 at 23:14




3




3




The regex for the general case of a range is very ugly, long and painful to write. Regex is not the best tool for the job. I recommend converting to a single integer value (for example, the number of seconds since midnight, or since the last hour, etc) and check if the value is within low/high values using math.
– Bohemian
Nov 8 at 23:25




The regex for the general case of a range is very ugly, long and painful to write. Regex is not the best tool for the job. I recommend converting to a single integer value (for example, the number of seconds since midnight, or since the last hour, etc) and check if the value is within low/high values using math.
– Bohemian
Nov 8 at 23:25




1




1




What exactly is your question? Do you want to know how to create such regex?
– JojOatXGME
Nov 9 at 23:00




What exactly is your question? Do you want to know how to create such regex?
– JojOatXGME
Nov 9 at 23:00












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Generally, using a regular expressions is probably not the best solution. Depending on the tools, there might be better solutions. However, it is somewhat possible.



How to create the regex



Let's assume our timecodes do always have the following format: mm:ss. You might want to match all timecodes from 22:22 to 77:77. This means the regex shall match when one of the following statements is true.



  • Timecode starts with 2 and the rest of the string is 2:22 or higher.

  • Timecode starts with 3, 4, 5 or 6.

  • Timecode starts with 7 and the the rest of the string is 7:77 or lower.

This means at least one the following three regular expressions must match:



  • /22:22 or higher/

  • /[3-6]d:dd/

  • /77:77 or lower/

This means the final regular expression would look something like the following. The parts surrounded by curly braces () will be resolved later.



/22:22 or higher|[3-6]d:dd|77:77 or lower/


Now, we have to resolve 2:22 or higher and 7:77 or lower. A string of the form x:xx is 2:22 or higher, when one of the following statements are true.



  • The string starts with 2: and the rest of the string is 22 or higher.

  • The string starts with 3, 4, 5, 6, 7, 8 or 9.

Therefore, 2:22 or higher can be written as



/2:22 or higher|[3-9]:dd/


Now we have the following.



/2(2:22 or higher|[3-9]:dd)|[3-6]d:dd|77:77 or lower/


You can repeat this steps until no parts surrounded by curly braces () are left. The result might look as below.



/2(2:(2[2-9]|[3-9]d)|[3-9]:dd)|[3-6]d:dd|7(7:(7[0-7]|[0-6]d)|[0-6]:dd)/


https://regex101.com/r/AsfRQt/1/tests






share|improve this answer






















  • This is really cool, thanks a lot. I was stuck at this stage before I saw your answer (([0-5].[0-9]?|60)(?:[:])([0-5].[0-9]?|60))... Far from the solution! Thanks again
    – Asten Mies
    Nov 10 at 1:27










  • @AstenMies I just realized that having a timecode with more then 60 seconds behind the colon is not very reasonable. :D However, I guess the procedure is still comprehensible.
    – JojOatXGME
    Nov 10 at 9:52










  • Yep I thought you must have a very unusual watch ;) But indeed it doesn't matter much, it's comprehensible
    – Asten Mies
    Nov 10 at 19:15










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217357%2fmatch-all-timecodes-between-two-timecodes%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Generally, using a regular expressions is probably not the best solution. Depending on the tools, there might be better solutions. However, it is somewhat possible.



How to create the regex



Let's assume our timecodes do always have the following format: mm:ss. You might want to match all timecodes from 22:22 to 77:77. This means the regex shall match when one of the following statements is true.



  • Timecode starts with 2 and the rest of the string is 2:22 or higher.

  • Timecode starts with 3, 4, 5 or 6.

  • Timecode starts with 7 and the the rest of the string is 7:77 or lower.

This means at least one the following three regular expressions must match:



  • /22:22 or higher/

  • /[3-6]d:dd/

  • /77:77 or lower/

This means the final regular expression would look something like the following. The parts surrounded by curly braces () will be resolved later.



/22:22 or higher|[3-6]d:dd|77:77 or lower/


Now, we have to resolve 2:22 or higher and 7:77 or lower. A string of the form x:xx is 2:22 or higher, when one of the following statements are true.



  • The string starts with 2: and the rest of the string is 22 or higher.

  • The string starts with 3, 4, 5, 6, 7, 8 or 9.

Therefore, 2:22 or higher can be written as



/2:22 or higher|[3-9]:dd/


Now we have the following.



/2(2:22 or higher|[3-9]:dd)|[3-6]d:dd|77:77 or lower/


You can repeat this steps until no parts surrounded by curly braces () are left. The result might look as below.



/2(2:(2[2-9]|[3-9]d)|[3-9]:dd)|[3-6]d:dd|7(7:(7[0-7]|[0-6]d)|[0-6]:dd)/


https://regex101.com/r/AsfRQt/1/tests






share|improve this answer






















  • This is really cool, thanks a lot. I was stuck at this stage before I saw your answer (([0-5].[0-9]?|60)(?:[:])([0-5].[0-9]?|60))... Far from the solution! Thanks again
    – Asten Mies
    Nov 10 at 1:27










  • @AstenMies I just realized that having a timecode with more then 60 seconds behind the colon is not very reasonable. :D However, I guess the procedure is still comprehensible.
    – JojOatXGME
    Nov 10 at 9:52










  • Yep I thought you must have a very unusual watch ;) But indeed it doesn't matter much, it's comprehensible
    – Asten Mies
    Nov 10 at 19:15














up vote
1
down vote



accepted










Generally, using a regular expressions is probably not the best solution. Depending on the tools, there might be better solutions. However, it is somewhat possible.



How to create the regex



Let's assume our timecodes do always have the following format: mm:ss. You might want to match all timecodes from 22:22 to 77:77. This means the regex shall match when one of the following statements is true.



  • Timecode starts with 2 and the rest of the string is 2:22 or higher.

  • Timecode starts with 3, 4, 5 or 6.

  • Timecode starts with 7 and the the rest of the string is 7:77 or lower.

This means at least one the following three regular expressions must match:



  • /22:22 or higher/

  • /[3-6]d:dd/

  • /77:77 or lower/

This means the final regular expression would look something like the following. The parts surrounded by curly braces () will be resolved later.



/22:22 or higher|[3-6]d:dd|77:77 or lower/


Now, we have to resolve 2:22 or higher and 7:77 or lower. A string of the form x:xx is 2:22 or higher, when one of the following statements are true.



  • The string starts with 2: and the rest of the string is 22 or higher.

  • The string starts with 3, 4, 5, 6, 7, 8 or 9.

Therefore, 2:22 or higher can be written as



/2:22 or higher|[3-9]:dd/


Now we have the following.



/2(2:22 or higher|[3-9]:dd)|[3-6]d:dd|77:77 or lower/


You can repeat this steps until no parts surrounded by curly braces () are left. The result might look as below.



/2(2:(2[2-9]|[3-9]d)|[3-9]:dd)|[3-6]d:dd|7(7:(7[0-7]|[0-6]d)|[0-6]:dd)/


https://regex101.com/r/AsfRQt/1/tests






share|improve this answer






















  • This is really cool, thanks a lot. I was stuck at this stage before I saw your answer (([0-5].[0-9]?|60)(?:[:])([0-5].[0-9]?|60))... Far from the solution! Thanks again
    – Asten Mies
    Nov 10 at 1:27










  • @AstenMies I just realized that having a timecode with more then 60 seconds behind the colon is not very reasonable. :D However, I guess the procedure is still comprehensible.
    – JojOatXGME
    Nov 10 at 9:52










  • Yep I thought you must have a very unusual watch ;) But indeed it doesn't matter much, it's comprehensible
    – Asten Mies
    Nov 10 at 19:15












up vote
1
down vote



accepted







up vote
1
down vote



accepted






Generally, using a regular expressions is probably not the best solution. Depending on the tools, there might be better solutions. However, it is somewhat possible.



How to create the regex



Let's assume our timecodes do always have the following format: mm:ss. You might want to match all timecodes from 22:22 to 77:77. This means the regex shall match when one of the following statements is true.



  • Timecode starts with 2 and the rest of the string is 2:22 or higher.

  • Timecode starts with 3, 4, 5 or 6.

  • Timecode starts with 7 and the the rest of the string is 7:77 or lower.

This means at least one the following three regular expressions must match:



  • /22:22 or higher/

  • /[3-6]d:dd/

  • /77:77 or lower/

This means the final regular expression would look something like the following. The parts surrounded by curly braces () will be resolved later.



/22:22 or higher|[3-6]d:dd|77:77 or lower/


Now, we have to resolve 2:22 or higher and 7:77 or lower. A string of the form x:xx is 2:22 or higher, when one of the following statements are true.



  • The string starts with 2: and the rest of the string is 22 or higher.

  • The string starts with 3, 4, 5, 6, 7, 8 or 9.

Therefore, 2:22 or higher can be written as



/2:22 or higher|[3-9]:dd/


Now we have the following.



/2(2:22 or higher|[3-9]:dd)|[3-6]d:dd|77:77 or lower/


You can repeat this steps until no parts surrounded by curly braces () are left. The result might look as below.



/2(2:(2[2-9]|[3-9]d)|[3-9]:dd)|[3-6]d:dd|7(7:(7[0-7]|[0-6]d)|[0-6]:dd)/


https://regex101.com/r/AsfRQt/1/tests






share|improve this answer














Generally, using a regular expressions is probably not the best solution. Depending on the tools, there might be better solutions. However, it is somewhat possible.



How to create the regex



Let's assume our timecodes do always have the following format: mm:ss. You might want to match all timecodes from 22:22 to 77:77. This means the regex shall match when one of the following statements is true.



  • Timecode starts with 2 and the rest of the string is 2:22 or higher.

  • Timecode starts with 3, 4, 5 or 6.

  • Timecode starts with 7 and the the rest of the string is 7:77 or lower.

This means at least one the following three regular expressions must match:



  • /22:22 or higher/

  • /[3-6]d:dd/

  • /77:77 or lower/

This means the final regular expression would look something like the following. The parts surrounded by curly braces () will be resolved later.



/22:22 or higher|[3-6]d:dd|77:77 or lower/


Now, we have to resolve 2:22 or higher and 7:77 or lower. A string of the form x:xx is 2:22 or higher, when one of the following statements are true.



  • The string starts with 2: and the rest of the string is 22 or higher.

  • The string starts with 3, 4, 5, 6, 7, 8 or 9.

Therefore, 2:22 or higher can be written as



/2:22 or higher|[3-9]:dd/


Now we have the following.



/2(2:22 or higher|[3-9]:dd)|[3-6]d:dd|77:77 or lower/


You can repeat this steps until no parts surrounded by curly braces () are left. The result might look as below.



/2(2:(2[2-9]|[3-9]d)|[3-9]:dd)|[3-6]d:dd|7(7:(7[0-7]|[0-6]d)|[0-6]:dd)/


https://regex101.com/r/AsfRQt/1/tests







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 0:22

























answered Nov 9 at 23:59









JojOatXGME

879923




879923











  • This is really cool, thanks a lot. I was stuck at this stage before I saw your answer (([0-5].[0-9]?|60)(?:[:])([0-5].[0-9]?|60))... Far from the solution! Thanks again
    – Asten Mies
    Nov 10 at 1:27










  • @AstenMies I just realized that having a timecode with more then 60 seconds behind the colon is not very reasonable. :D However, I guess the procedure is still comprehensible.
    – JojOatXGME
    Nov 10 at 9:52










  • Yep I thought you must have a very unusual watch ;) But indeed it doesn't matter much, it's comprehensible
    – Asten Mies
    Nov 10 at 19:15
















  • This is really cool, thanks a lot. I was stuck at this stage before I saw your answer (([0-5].[0-9]?|60)(?:[:])([0-5].[0-9]?|60))... Far from the solution! Thanks again
    – Asten Mies
    Nov 10 at 1:27










  • @AstenMies I just realized that having a timecode with more then 60 seconds behind the colon is not very reasonable. :D However, I guess the procedure is still comprehensible.
    – JojOatXGME
    Nov 10 at 9:52










  • Yep I thought you must have a very unusual watch ;) But indeed it doesn't matter much, it's comprehensible
    – Asten Mies
    Nov 10 at 19:15















This is really cool, thanks a lot. I was stuck at this stage before I saw your answer (([0-5].[0-9]?|60)(?:[:])([0-5].[0-9]?|60))... Far from the solution! Thanks again
– Asten Mies
Nov 10 at 1:27




This is really cool, thanks a lot. I was stuck at this stage before I saw your answer (([0-5].[0-9]?|60)(?:[:])([0-5].[0-9]?|60))... Far from the solution! Thanks again
– Asten Mies
Nov 10 at 1:27












@AstenMies I just realized that having a timecode with more then 60 seconds behind the colon is not very reasonable. :D However, I guess the procedure is still comprehensible.
– JojOatXGME
Nov 10 at 9:52




@AstenMies I just realized that having a timecode with more then 60 seconds behind the colon is not very reasonable. :D However, I guess the procedure is still comprehensible.
– JojOatXGME
Nov 10 at 9:52












Yep I thought you must have a very unusual watch ;) But indeed it doesn't matter much, it's comprehensible
– Asten Mies
Nov 10 at 19:15




Yep I thought you must have a very unusual watch ;) But indeed it doesn't matter much, it's comprehensible
– Asten Mies
Nov 10 at 19:15

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217357%2fmatch-all-timecodes-between-two-timecodes%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus