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.
Fields of activity: Legal basis:
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).
if ($content=~/Fields\sof\sactivity:(.*)\n\nLegal/s) {$d_fieldofactivi +ty=$1;} else {$d_fieldofactivity='missing';}
The same happens with this code (maybe matching the two new lines does not work for some reason???):
if ($content=~/Fields\sof\sactivity:(.*)Legal/s) {$d_fieldofactivity=$ +1;} else {$d_fieldofactivity='missing';}
And with this code (maybe the problem is with words right after new line???):
if ($content=~/Fields\sof\sactivity:(.*)basis/s) {$d_fieldofactivity=$ +1;} else {$d_fieldofactivity='missing';}
Helpful suggestions would be appreciated!
In reply to Regular expression with multiple lines by PerlNovice999
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |