in reply to regular expression
If you really wanted to do it with a single regular expression you'd need to slurp the file, and that's not recommended because it doesn't scale well. However, the flip flop operator (scalar context range operator - ..) provides an interesting solution:
use warnings; use strict; while (<DATA>) { print if s/{AUTHOR}\n// .. (s/{AUTHOR}\n//, s/{(?!AUTHOR})\w+}\n// +); } __DATA__ {TAG} tag1 {AUTHOR} By June Fletcher JOURNAL {TAG} tag2 TOM MacCUBBIN {DATA} data1 {AUTHOR} Richard White {AUTHOR} MacCUBBIN {SOUR}
Prints:
By June Fletcher JOURNAL Richard White MacCUBBIN
|
|---|