Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8538305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:06:09+00:00 2026-06-11T11:06:09+00:00

I am trying to match a 24 hour time with regular expressions using egrep.

  • 0

I am trying to match a 24 hour time with regular expressions using egrep.

Here is my test file, test.txt:

32:23:31
24:30:31
23:70:31
23:61:31
23:10:70
23:10:61
22:17:16
01:17:15
24:15:22
0:17:16
00:17:17
24:30:31

Here is my regular expression:

egrep '(2[0-3]|1[0-9]|0[0-9]|[^0-9][0-9]):([0-5][0-9]|[0-9]):([0-5][0-9]|[0-9])' test.txt

Resulting matches:

23:10:70
23:10:61
22:17:16
01:17:15
00:17:17

Any idea why it is matching 23:10:70 and 23:10:61?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:06:10+00:00Added an answer on June 11, 2026 at 11:06 am

    It’s actually matching 23:10:7 and 23:10:6, but since you are not using the end of line metacharacter $ at the end of the string, it will process anything that follows.

    egrep '^(2[0-3]|1[0-9]|0[0-9]|[^0-9][0-9]):([0-5][0-9]|[0-9]):([0-5][0-9]|[0-9])$' test.txt
    

    In other words, you should only allow [0-9] at the end of the string, if the matched digit is the last one on the line, that is, if it is followed by $.

    Another option, is to force the last digit to be 0-padded if it is less than 10, i.e., instead of [0-9] use 0[0-9]. This will match 23:10:07, but not 23:10:7. It’s the same you already have for the hours part.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to match floating-point decimal numbers with a regular expression. There may
I'm trying to match expressions that start with PRE and end with PRE. I'm
I am trying to match for country or Country using lower-case function in XPath.
I am trying to match the text contents(character data) of an XML file with
I am trying to match 190 in the following ~ delimited text file GPSE~21~ADVANCED
I'm trying to match an email address here is what I've come up with
I'm trying to build a regular expression that will catch one of three patterns
I'm trying to match elements with a name that is 'container1$container2$chkChecked' , using a
I'm trying to match the parts of a version number (Major.Minor.Build.Revision) with C# regular
I'm trying to match a word using regex that has numbers in it, for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.