|Perl Monk, Perl Meditation|
Regular expression with multiple linesby PerlNovice999 (Novice)
|on Sep 25, 2013 at 07:18 UTC||Need Help??|
PerlNovice999 has asked for the
wisdom of the Perl Monks concerning the following question:
Dear Enlightened Ones!
I am extracting some data from a website and am stuck with the following (rather strange) problem. The website has several entries which are always in the same order (and after stripping the html seperated by two new lines). Sometimes a category has no entries, sometimes the entry spans more than one line. So my general strategy is to extract the text between the two category labels using the .* to match any text and using \s to match text if it spans several lines. My problem is that the matching with the next category label, which should be the end of the extracted text, is not recognized. Instead, the rest of the file is returned.
Here is the relevant part of the text from which I am extracting (the text continues after this section). In this case, there is no entry for fields of activity.
Thus, the regular expression should either not be triggered at all (there is no text) or it should just include white space or new lines. Instead, the following code returns the rest of the file (including the string "Legal" which should demarcate the end of the extracted bit).
The same happens with this code (maybe matching the two new lines does not work for some reason???):
And with this code (maybe the problem is with words right after new line???):
Helpful suggestions would be appreciated!