Match all timecodes between two timecodes
up vote
3
down vote
favorite
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
|
show 3 more comments
up vote
3
down vote
favorite
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
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
|
show 3 more comments
up vote
3
down vote
favorite
up vote
3
down vote
favorite
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
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
javascript regex
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
|
show 3 more comments
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
|
show 3 more comments
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
2and the rest of the string is2:22or higher. - Timecode starts with
3,4,5or6. - Timecode starts with
7and the the rest of the string is7:77or 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 is22or higher. - The string starts with
3,4,5,6,7,8or9.
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
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
add a comment |
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
2and the rest of the string is2:22or higher. - Timecode starts with
3,4,5or6. - Timecode starts with
7and the the rest of the string is7:77or 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 is22or higher. - The string starts with
3,4,5,6,7,8or9.
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
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
add a comment |
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
2and the rest of the string is2:22or higher. - Timecode starts with
3,4,5or6. - Timecode starts with
7and the the rest of the string is7:77or 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 is22or higher. - The string starts with
3,4,5,6,7,8or9.
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
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
add a comment |
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
2and the rest of the string is2:22or higher. - Timecode starts with
3,4,5or6. - Timecode starts with
7and the the rest of the string is7:77or 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 is22or higher. - The string starts with
3,4,5,6,7,8or9.
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
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
2and the rest of the string is2:22or higher. - Timecode starts with
3,4,5or6. - Timecode starts with
7and the the rest of the string is7:77or 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 is22or higher. - The string starts with
3,4,5,6,7,8or9.
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
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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