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

  Quote
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.