Jump to content

Capture every line after a particular line


Jerred121

Recommended Posts

I want a pattern that will match every line after a particular line - the only constant that I can rely on is that if the header is there I know I want the follow lines. It doesn't matter if I end up getting more lines than I want because I'll only take the first however many I need.

 

SURGICAL/MEDICAL HISTORY <--Header to indicate the beginning of my list
HISTORY 1 <--line1 to be matched
HISTORY 2 <--line2 to be matched
HISTORY 3 <--line3 to be matched
.
.

 

I'm not posting a real sample of the text because it shouldn't matter - the pattern must be flexible and for other particular reasons. I just always have such an issue with lines in regex. Here is what I have:

$ptn = "/SURGICAL\/MEDICAL HISTORY\s*(^(.+)$)+/m";

 

I need all of the matched lines in separated in an array:

 

Array
(
    [0] => Array
        (
            [0] => SURGICAL/MEDICAL HISTORY
HISTORY 1
HISTORY 2
        )

    [1] => Array
        (
            [0] => HISTORY 1
            [1] => HISTORY 2
        )

)

 

Thanks for any suggestions

Link to comment
Share on other sites

I want a pattern that will match every line after a particular line
I got it working though.  I used strstr to parse the string a the line that I wanted and performed the preg_match on the parsed string.  Less "elegant"than just one REGEX pattern, but it works.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.