0

Possible Duplicate:
PHP REGEX preg_math_all every line after a particular line

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";

But that only matches the first line. Thanks!

EDIT: 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
        )

)
0

1 Answer 1

2

This might be useful : Pattern Modifiers

s (PCRE_DOTALL)

If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.

Your final regex should look like this (not tested) :

$ptn = "/SURGICAL\/MEDICAL HISTORY\s*$(.*)/ms";
Sign up to request clarification or add additional context in comments.

1 Comment

problem with that is I need to match the lines separately, what that does it is just returns them all in one key.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.