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

  • Home
  • SEARCH
  • 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 7552667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:50:22+00:00 2026-05-30T10:50:22+00:00

After hours of trying to wrap my head around pattern matching, I’m throwing the

  • 0

After hours of trying to wrap my head around pattern matching, I’m throwing the towel in and turning to the experts…

I have a log file that I’m trying to extract a string from.

The format is like:

12:00 SomeText:
1:20 MoreText:

The “SomeText/MoreText” is what I need to get. I’ve come up with the code below but not getting anything near the results I’m expecting:

$string = "12:00 SomeText: blah, blah, blah not important";
$regex = '/[0-9]:[0-9] (.*?)\: /';
$entity = preg_split($regex, $string);

The regex logic as I understand it is, any number, followed by a colon, followed by any number, followed by white space, the text, followed be a colon, followed by white space

A push in the right direction would be greatly appreciated!

Thanks
Chris

  • 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-05-30T10:50:24+00:00Added an answer on May 30, 2026 at 10:50 am

    You are matching a single digit, a colon, then a single digit.

    $string = "12:00 SomeText: blah, blah, blah not important";
    $regex = '/[0-9]+:[0-9]+ ([^:]+)/';
    $entity = array();
    preg_match($regex, $string, $entity);
    

    This will match one or more digits, a colon, one or more digits, the rest. preg_match will put the entire matching expression (12:00 Some Text) in position 0, and the matched subexpressions (Some Text) after that, so your “Some Text” will be in $entity[1]

    [Edit]
    After the discussion in the comments, I’ve improved the matching against the header. Before, you had

    (.*?)\:
    

    which will find any character, up to the end of the string, optionally, and then backtrack until it finds the colon. I’ve replaced it with

    ([^:]+)
    

    which will find one or more characters that are not colons, and match them. This saves the regex from looking at “blah, blah, blah…” and then ignoring what it just found.

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

Sidebar

Related Questions

I've been trying to wrap my head around this issue for the last hours
I'm currently trying to wrap my head around WPF, and I'm at the stage
Ok, after two hours of trying, Im gonna ask... I have an app and
Right I have given in, after about 2 hours trying to figure out this
Well, after hours of trying to find something out, I have to ask here
I am asking for help, after hours of trying to figure this out myself.
After some hours of trying, I want to ask how to loop a video
OK I give up - after 5 solid hours trying to get a django
im trying to customize this page indicator with half succes, but after many hours
I am so frustrated right now after several hours trying to find where shared_ptr

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.