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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:37:26+00:00 2026-06-08T13:37:26+00:00

Here are some examples: Some text A Some text A 8:00-19:00 8:00-19:00 Some text

  • 0

Here are some examples:

  1. Some text A
  2. Some text A 8:00-19:00
  3. 8:00-19:00
  4. Some text A 8:00-19:00 Some text B

For each case described above, I need to capture (if possible):

  • The time (8:00-19:00)
  • The beginning (Some text A)
  • The end (Some text B)

With this pattern #^(.*?) ?(\d{1,2}:\d{2}-\d{1,2}:\d{2})?$#, I can capture (from example 2):

  • Some text A
  • 8:00-19:00

But I can’t capture the rest of the line by adding (.*) or (.*?) at the end of the pattern.

Can you help me? Thank you!

  • 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-08T13:37:27+00:00Added an answer on June 8, 2026 at 1:37 pm

    I think your main problem is that you’ve made the group of digits optional by adding ? after it (which I don’t think you want).

    This works for me /^(.*) ?(\d{1,2}:\d{2}-\d{1,2}:\d{2}) ?(.*)$/:

    <?
    
    $str = "Some text A 8:00-19:00 Some text B";
    $pat = "/^(.*) ?(\d{1,2}:\d{2}-\d{1,2}:\d{2}) ?(.*)$/";
    
    if(preg_match($pat, $str, $matches)){
       /*
    
        Cases 2, 3 and 4
    
        Array
        (
            [0] => Some text A 8:00-19:00 Some text B
            [1] => Some text A 
            [2] => 8:00-19:00
            [3] => Some text B
        )
    
       */
    }else{
       /* Case 1 */
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

php newbie here..I need some PHP help ideas/examples on how to import data from
Here are some examples of strings (mainly addresses): 12 20 43-B 43-C 123 2500
I'd like to draw some statistics charts using QT4.7 , here are some examples:
Im trying to hammer togehter a WYSIWYG-edit in c# following some examples from here
For example (in my case) here's some code, <?php woo_post_inside_before(); if ( $woo_options['woo_post_content'] !=
I have a html table similar to this: <table> <tr> <td>1</td> <td>Some text...</td> </tr>
Here is an example: <div><span style=font-size:15px;>some text here which is </span> <span style=color:red;>split automatically
Here's some example code: class Obj attr :c, true def == that p '=='
Here is some example data: data = data.frame(series = c(1a, 1b, 1e), reading =
Just some example code here, but I have lists of strings that I want

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.