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 9009737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:16:42+00:00 2026-06-16T02:16:42+00:00

I have a pattern like (any text) XX:XX AM – XX:XX PM (any text)

  • 0

I have a pattern like

(any text) XX:XX AM – XX:XX PM (any text)

where X is a number between 0 and 9 and the number can 1 or two character (ex: 12:45 or 1:20)

I need to find a regex to find the – (dash character) in between that pattern.

I’m new but this was my simple RegEx to find the above pattern:

([\d]{1,2}:[\d]{1,2}|[\d]{1,2}:[\d]{1,2} [aApP][mM])(.*?)([\d]{1,2}:[\d]{1,2}|[\d]{1,2}:[\d]{1,2} [aApP][mM])

This doesn’t get me my ultimate goal of just finding the dash in the middle of the pattern.

  • 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-16T02:16:43+00:00Added an answer on June 16, 2026 at 2:16 am

    Positive look-behind will be the shortest/simplest regexp for this situation but it’s not support everywhere so it will depend on what language/environment you are using.

    Match only the - following AM:

    (?<=AM )-
    

    Depending on the likely-hood of false positives in your data this might need to be tighten up, such as HAM - CHEESE will also match, so using positive look-behind and look-ahead:

    (?<=:\d{2} AM )-(?= \d{1,2}:\d{2} PM)
    
    ?<=      # Positive look-behind 
    :        # Match colon
    \d{2}    # Followed by 2 digits (and a space)
    AM       # Followed by AM (and a space)
    -        # Match hyphen if look-behind is met
    ?=       # Positive look-ahead
     \d{1,2} # Match either 1 or 2 digits
    :        # Followed by a colon 
    \d       # Followed by 2 more digits 
     PM      # Finally a space and PM   
    

    That should rule out any false positives.

    Demo with grep:

    $ echo '(any text) XX:XX AM - XX:XX PM (any text)' | grep -Po '(?<=AM )-'
    -
    
    $ echo '12:45 AM - 1:20 PM' | grep -Po '(?<=:\d{2} AM )-(?= \d{1,2}:\d{2} PM)'
    -
    

    Another option is using capture groups, the following regexp will match the whole line and the - will be matched in capture group 1:

    ^.*\d{1,2}:\d{2}\sAM\s(-)\s\d{1,2}:\d{2}\sPM.*$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need my select to have a pattern like this: SELECT '<text> ' +
I have compared a text file with a pattern like .. and i need
I have code like this string pattern = <(.|\n)+?>; System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Reg(pattern);
I've been searching for at least 2hrs but I can't find any pattern to
I would like to find text which is between the < and > characters,
I have problems with pattern. I need to process some text for example: <div>{text1}</div><span>{text2}</span>
I have pattern like below hi hello hallo greetings salutations no more hello for
I have a timedate string in a round-trip data pattern like this: 2012-07-05T11:30:44.1533815Z .
Just I am learning Generics.When i have an Abstract Method pattern like : //Abstract
For one NSString, I have N pattern strings. I'd like to extract substrings around

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.