in reply to I need to regex multiple lines
There are two regex modifiers that help. /s so that . matches \n and /m so that ^ and $ match at the start and end of logical lines. /x allows free formating and embedded comments.
Using these modifiers you regex can be written as
which will create an array withmy @array = $line =~ m{ ^(LENGTH: # a line beginning with LENGTH: .*?) # as little as possible until ^(SUBJECT: # a line beginning with SUBJECT: .*?) # as little as possible until ^(COMMENT: # a line beggining with COMMENT .*) # and the rest }msx
$VAR1 = [ 'LENGTH: ................................................... +... .................................................................. .................................................................. ................................................................... .................................................................. ', 'SUBJECT: .................................................. +..... ', 'COMMENT: .................................................. +... .................................................................... ' ];
|
|---|