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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:39:08+00:00 2026-05-11T17:39:08+00:00

I’m trying to parse a log file that looks like this: %%%% 09-May-2009 04:10:29

  • 0

I’m trying to parse a log file that looks like this:

%%%% 09-May-2009 04:10:29
% Starting foo
this is stuff
to ignore
%%%% 09-May-2009 04:10:50
% Starting bar
more stuff
to ignore
%%%% 09-May-2009 04:11:29
...

This excerpt contains two time periods I’d like to extract, from the first delimiter to the second, and from the second to the third. I’d like to use a regular expression to extract the start and stop times for each of these intervals. This mostly works:

p = '%{4} (?<start>.*?)\n% Starting (?<name>.*?)\n.*?%{4} (?<stop>.*?)\n';
times = regexp(c,p,'names');

Returning:

times = 

1x16 struct array with fields:
    start
    name
    stop

The problem is that this only captures every other period, since the second delimiter is consumed as part of the first match.

In other languages, you can use lookaround operators (lookahead, lookbehind) to solve this problem. The documentation on regular expressions explains how these work in MATLAB, but I haven’t been able to get these to work while still capturing the matches. That is, I not only need to be able to match every delimiter, but also I need to extract part of that match (the timestamp).

Is this possible?

P.S. I realize I can solve this problem by writing a simple state machine or by matching on the delimiters and post-processing, if there’s no way to get this to work.

Update: Thanks for the workaround ideas, everyone. I heard from the developer and there’s currently no way to do this with the regular expression engine in MATLAB.

  • 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-11T17:39:08+00:00Added an answer on May 11, 2026 at 5:39 pm

    MATLAB seems unable to capture characters as a token without removing them from the string (or, I should say, I was unable to do so using MATLAB REGEXP). However, by noting that the stop time for one block of text is equal to the start time of the next, I was able to capture just the start times and the names using REGEXP, then do some simple processing to get the stop times from the start times. I used the following sample text:

    c =
    
    %%%% 09-May-2009 04:10:29
    % Starting foo
    this is stuff
    to ignore
    %%%% 09-May-2009 04:10:50
    % Starting bar
    more stuff
    to ignore
    %%%% 09-May-2009 04:11:29
    some more junk
    

    …and applied the following expression:

    p = '%{4} (?<start>[^\n]*)\n% Starting (?<name>[^\n]*)[^%]*|%{4} (?<start>[^\n]*).*';
    

    The processing can then be done with the following code:

    names = regexp(c,p,'names');
    [names.stop] = deal(names(2:end).start,[]);
    names = names(1:end-1);
    

    …which gives us these results for the above sample text:

    >> names(1)
    
    ans = 
    
        start: '09-May-2009 04:10:29'
         name: 'foo'
         stop: '09-May-2009 04:10:50'
    
    >> names(2)
    
    ans = 
    
        start: '09-May-2009 04:10:50'
         name: 'bar'
         stop: '09-May-2009 04:11:29'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
i want to parse a xhtml file and display in UITableView. what is the

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.