March 20th, 2013, 05:08 PM
Because your problem involves a little bit more that pure regexes, it would be important to know in which language you are working. The solution mght be very different depending on the language used.
For example in Perl, I could just do something as simple as this
- Perl Code
my $input = "string\n12312\nasd\nstring fsdsg\nasgsdgfd sdfsd\n<saef 12n\af> sf \n123\nstring\n123\nstring gasfsfdsg\n";
Now, the @foo array contains four elements, the first one empty because string comes right at the beginning (easy to solve if this is nor desired) and then the three chunks you are looking for:
2 " fsdsg\cJasgsdgfd sdfsd\cJ<saef 12n\cGf> sf \cJ123\cJ"
4 ' gasfsfdsg
But this very easy solution depends on the language being used (but I am sure other languages have similar facilities).