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 Link to comment https://forums.phpfreaks.com/topic/229539-capture-every-line-after-a-particular-line/ 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)+/ Link to comment https://forums.phpfreaks.com/topic/229539-capture-every-line-after-a-particular-line/#findComment-1182633 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. Link to comment https://forums.phpfreaks.com/topic/229539-capture-every-line-after-a-particular-line/#findComment-1182951 Share on other sites More sharing options...
RussellReal Posted March 4, 2011 Share Posted March 4, 2011 don't understand what you want then Link to comment https://forums.phpfreaks.com/topic/229539-capture-every-line-after-a-particular-line/#findComment-1183035 Share on other sites More sharing options...
Jerred121 Posted March 6, 2011 Author Share Posted March 6, 2011 Quote 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. Link to comment https://forums.phpfreaks.com/topic/229539-capture-every-line-after-a-particular-line/#findComment-1183474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.