Jerred121 Posted March 3, 2011 Share Posted March 3, 2011 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 Link to comment Share on other sites More sharing options...
RussellReal Posted March 4, 2011 Share Posted March 4, 2011 you could probably try a pattern like this:) /^(:.*?\n){numOfLinesToSkip}(?.*)\n)+/ Quote Link to comment Share on other sites More sharing options...
Jerred121 Posted March 4, 2011 Author Share Posted March 4, 2011 problem is that i don't know how many lines to skip. Quote Link to comment Share on other sites More sharing options...
RussellReal Posted March 4, 2011 Share Posted March 4, 2011 don't understand what you want then Quote Link to comment Share on other sites More sharing options...
Jerred121 Posted March 6, 2011 Author Share Posted March 6, 2011 I want a pattern that will match every line after a particular lineI 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.